I'm trying to get data from database. When I click on item in listview it should get me all data for clicked item. but I'm getting this error and cannot resolve it.
FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{http://ift.tt/1M1LH9f}: android.database.sqlite.SQLiteException: near "SELECT": syntax error (code 1): , while compiling: SELECT * FROM Logs WHERE id IN SELECT id FROM logs_recepits WHERE id =?
Caused by: android.database.sqlite.SQLiteException: near "SELECT": syntax error (code 1): , while compiling: SELECT * FROM Logs WHERE id IN SELECT id FROM logs_recepits WHERE id =?
public ArrayList<Logs> getAllLogs(long id) {
ArrayList<Logs> logList = new ArrayList<Logs>();
String selectQuery = "SELECT * FROM " + TABLE_LOGS + " WHERE " + KEY_ID + " IN " + ( "SELECT " + KEY_ID + " FROM " + TABLE_LOGS_BELONGS_TO_RECEPIT + " WHERE " + RECEPIT_ID + " =?");
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, new String[]{String.valueOf(id)});
//going throug all rows and adding it to list
if (cursor.moveToFirst()) {
do {
Logs log = new Logs();
log.setId(cursor.getLong(0));
log.setCreatedAt(cursor.getString(1));
log.setPlate_number(cursor.getString(2));
log.setSort_id(cursor.getString(3));
log.setGrade(cursor.getString(4));
log.setDiameter(cursor.getString(5));
log.setLength(cursor.getString(6));
logList.add(log);
}while (cursor.moveToNext());
}
return logList;
}
Question: How should I resolve this error?
Aucun commentaire:
Enregistrer un commentaire