【问题标题】:Syntax error sqlite inner join语法错误 sqlite 内连接
【发布时间】:2014-02-08 13:05:54
【问题描述】:

这是我在数据库解决方案中的代码

public HashMap<String, String> getBookTheme(){

    HashMap<String, String> hm = new HashMap<String, String>();
    Cursor cursor = db.rawQuery("SELECT title, filepath FROM " + 
                BooksDBHelper.TABLE_BOOK + " INNER JOIN" + BooksDBHelper.TABLE_THEME +
                " ON " + BooksDBHelper.TABLE_BOOK + " . " + 
                BooksDBHelper.KEY_BOK_ID + " = " + BooksDBHelper.TABLE_THEME + 
                " . " + BooksDBHelper.KEY_BOK_ID, null);
    cursor.moveToLast();
    if(cursor.getCount() != 0){
        do{

            hm.put("title", cursor.getString(cursor.getColumnIndex(BooksDBHelper.KEY_TITLE)));
            hm.put("Theme", cursor.getString(cursor.getColumnIndex(BooksDBHelper.KEY_fILEPATH)));

        }while(cursor.moveToNext());

    }

    return hm;

}

这是我的 logcat 错误

android.database.sqlite.SQLiteException: near "ON": syntax error (code 1): , while compiling: SELECT title, filepath FROM books INNER JOINtheme ON books . bookID = theme . bookID WHERE bookID != ?

请检查并告诉我收集语法。感谢观看:))))

【问题讨论】:

    标签: android sqlite syntax-error inner-join


    【解决方案1】:

    JOIN 和表 1 名称之间没有空格 (" ")。表名和 .列名

    将其更改为:

    SELECT title, filepath FROM books INNER JOIN theme ON books.bookID = theme.bookID WHERE bookID != ?
    

    我想你会没事的。

    希望这会有所帮助。

    【讨论】:

    • 很高兴我能帮上忙 :) @user3001046
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多