Skip to content Skip to sidebar Skip to footer

Select Query In Sqlite Android

String temp_address='nothing'; try { String selectQuery = 'SELECT lastchapter FROM Bookdetails INTO'+temp_address+'WHERE bookpath=?'; db.execSQL(selectQuery

Solution 1:

There are SQL syntax problems and you'll need to use a Cursor to retrieve query results, for example with rawQuery():

StringselectQuery="SELECT lastchapter FROM Bookdetails WHERE bookpath=?";
Cursorc= db.rawQuery(selectQuery, newString[] { fileName });
if (c.moveToFirst()) {
    temp_address = c.getString(c.getColumnIndex("lastchapter"));
}
c.close();

Solution 2:

The logcat said it all, you've forgot spaces. To get data into the string:

String temp_address="nothing";
String[] args = newString[] { fileName };
Cursor cursor = sqLiteDatabase.rawQuery("SELECT lastchapter FROM Bookdetails WHERE bookpath=?", args);
if (cursor.moveToFirst()){
    temp_address = cursor.getString(cursor.getColumnIndex("lastchapter"));
}
cursor.close();

Solution 3:

Correct your query with below: add space at WHERE Cause

StringselectQuery="SELECT lastchapter FROM Bookdetails WHERE bookpath=? ";

Update: go with rawQuery() becoz it's return Cursor with results

StringselectQuery="SELECT lastchapter FROM Bookdetails WHERE bookpath=? ";
 Cursorc= db.rawQuery(selectQuery, newString[] { fileName });
 if (c.moveToFirst()) {
 temp_address = c.getString(0);
 }
  c.close();

And for more information go to this: http://www.higherpass.com/android/tutorials/accessing-data-with-android-cursors/

Post a Comment for "Select Query In Sqlite Android"