android - 在sqlite android中选择查询

标签 android sqlite

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();
    }

日志

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();

关于android - 在sqlite android中选择查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22169752/

相关文章:

java - 尝试从 Android 中的图库或相机获取图像

android - 当应用程序处于后台时,Firebase SDK 不会打开启动器 Activity

java - 如何使用带有加密功能的 SQLiteJDBC 库 (sqlite-jdbc-crypt)

android - 在 Android Studio 中查看设备上的 SQLite 数据库

android - ViewPager中Fragment来到屏幕时的方法

android - 在 [Scrollable Tabs + Swipe] Navigation-Android 中滚动时如何更新 Fragment?

android - TextView 在相对布局中不起作用

bash - SQLite,bash脚本和串联运算符

iphone sqlite 'unable to open database file' 有时

sql - 如果 sqlite 数据库包含具有相同名称/功能的多行,如何选择特定行