我正在尝试在我的手机上获取 SQLite 数据库值。数据在数据库中可用,但此游标类显示的值在数据库中不可用。我该如何解决问题?
这是databasehelper
调用函数
String imgname=img_name.getText().toString();
Cursor cursor = db.pname(imgname);
if(cursor.getCount()== 0)
{
Toast.makeText(getApplicationContext(), "Values are not available", Toast.LENGTH_SHORT).show();
}
else
{
while (cursor.moveToFirst())
{
Toast.makeText(getApplicationContext(), "name"+cursor.getColumnIndex("name"), Toast.LENGTH_SHORT).show();
}
}
cursor.close();
DatabaseHelpe
类
public Cursor pname(String imgname) {
String name = imgname.toString();
String sql = "select * from '"+MSG+"' where product='"+name+"'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(sql, null);
return cursor;
}
我期待我的产品的名称。我如何解决它?
不应MSG
在单引号中使用。您的查询应该是:
select * from tablename where ...
String sql = "select * from "+MSG+" where product='"+name+"'";
tablename
不能用单引号。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句