如何从数据库中获得的信息。我想执行此行
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;
}
上一篇:如何读取二级缓存的命中/错失率的Android(ARM)?错失、二级缓存、Andr、oid
下一篇:谷歌地图Android的API:SupportMapFragment VS MapFragment地图、Android、API、MapFragment