我是Android新手,现在尝试使用cursor
从SQLite
检索数据。如何解决我的selectQuery
?
List<Info> info=new ArrayList<Info>();
String selectQuery=("SELECT Weather, Date, Status, TimeIn_Info, TimeOut_Info FROM " + MyDatabaseHelper.TABLE_INFO + " WHERE Name = ?",new String{}(String.valueOf(name)));
database = dbHelper.getWritableDatabase();
Cursor cursor=database.rawQuery(selectQuery,null);
错误
Error:(77, 142) error: ')' expected
Error:(77, 143) error: <identifier> expected
Error:(77, 147) error: not a statement
Error:(77, 153) error: ';' expected
Error:(77, 177) error: ';' expected
答案 0 :(得分:0)
错误是由您的String select查询引起的。你的中间有一个逗号,没有任何意义。连接运算符为+
,而您没有,
此
String selectQuery=("SELECT Weather, Date, Status, TimeIn_Info, TimeOut_Info FROM " + MyDatabaseHelper.TABLE_INFO + " WHERE Name = ?",new String{}(String.valueOf(name)))
应该是
String selectQuery="SELECT Weather, Date, Status, TimeIn_Info, TimeOut_Info FROM " + MyDatabaseHelper.TABLE_INFO + " WHERE Name = ?";
然后你想要selectionArgs:
String[] selectionArgs = new String[] {String.valueOf(name)};
然后是rawQuery:
database = dbHelper.getWritableDatabase();
Cursor cursor=database.rawQuery(selectQuery,selectionArgs);