4
String temp_address="nothing";
    try
    {
        String selectQuery = "SELECT lastchapter FROM Bookdetails INTO"+temp_address+"WHERE bookpath=?";
        db.execSQL(selectQuery, new String[] { fileName });
        System.out.println(temp_address+" result of select Query");
    }

    catch(Exception e)
    {
        System.out.println(e+" is the error here");

    }
    finally
    {
        db.close();
    }

Logcat

android.database.sqlite.SQLiteException: near "bookpath": syntax error: , while compiling: SELECT lastchapter FROM Bookdetails INTOnothingWHERE bookpath=?

i just want to take the result of the above query so that the string stored in lastchapter is available in temp_address please help

i am new to android sqlite database please help

4
  • now this error android.database.sqlite.SQLiteException: near "INTO": syntax error: , while compiling: SELECT lastchapter FROM Bookdetails INTO nothing WHERE bookpath=? Commented Mar 4, 2014 at 11:06
  • see my update and try this way Commented Mar 4, 2014 at 11:18
  • your query should be: String selectQuery = "SELECT lastchapter FROM Bookdetails INTO "+temp_address+" WHERE bookpath=?"; Commented Mar 4, 2014 at 11:27
  • For any query, this helped me stackoverflow.com/a/5498403/2542175 Commented Mar 25, 2015 at 10:58

3 Answers 3

20

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

String selectQuery = "SELECT lastchapter FROM Bookdetails WHERE bookpath=?";
Cursor c = db.rawQuery(selectQuery, new String[] { fileName });
if (c.moveToFirst()) {
    temp_address = c.getString(c.getColumnIndex("lastchapter"));
}
c.close();
Sign up to request clarification or add additional context in comments.

Comments

3

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

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

1 Comment

thanks for the help, the first error is solved but now android.database.sqlite.SQLiteException: near "INTO": syntax error: , while compiling: SELECT lastchapter FROM Bookdetails INTO nothing WHERE bookpath=? i think there is a syntax error in my select query, i just want to get the value in temp_address
3

Correct your query with below: add space at WHERE Cause

String selectQuery = "SELECT lastchapter FROM Bookdetails WHERE bookpath=? ";

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

 String selectQuery = "SELECT lastchapter FROM Bookdetails WHERE bookpath=? ";
 Cursor c = db.rawQuery(selectQuery, new String[] { 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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.