如何从数据库中获取信息.我想执行这一行
String nom = db.execSQL("select name from person where id='+id+'");
任何人都可以纠正我这一行,以获得表人的姓名
解决方法:
如果您的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是String数据类型,请尝试此操作.
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;
}
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!