从数据库中获得源码信息 [英] get information from database sqlite
本文介绍了从数据库中获得源码信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从数据库中获得的信息。我想执行此行
how to get an information from the database. I want to execute this line
String nom = db.execSQL("select name from person where id='+id+'");
任何一个可以纠正我,此行从表中的人得到的人的名字
Can any one correct me this line to get the name of person from the table person
推荐答案
请试试这个,如果你的id是整数数据类型。
public String getResult(int id)
{
String name = null;
try
{
Cursor c = null;
c = db.rawQuery("select name from person where id="+id, null);
c.moveToFirst();
name = c.getString(c.getColumnIndex("name"));
c.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return name;
}
皮斯试试这个,如果你的id是字符串数据类型。
public String getResult(String id)
{
String name = null;
try
{
Cursor c = null;
c = db.rawQuery("select name from person where id=" + "\""+id+"\"", null);
c.moveToFirst();
name = c.getString(c.getColumnIndex("name"));
c.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return name;
}
这篇关于从数据库中获得源码信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文