Reputation: 1105
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
Upvotes: 4
Views: 59646
Reputation: 47817
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/
Upvotes: 3
Reputation: 11244
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();
Upvotes: 3
Reputation: 152917
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();
Upvotes: 20