在sqlite android中选择查询

前端之家收集整理的这篇文章主要介绍了在sqlite android中选择查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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=?

我只想获取上述查询的结果,以便存储在lastchapter中的字符串在temp_address中可用
请帮忙

我是android sqlite数据库的新手,请帮忙

解决方法

存在sql语法问题,您需要使用Cursor来检索查询结果,例如使用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();

猜你在找的Sqlite相关文章