2014-02-08 117 views
0

這是我在數據庫解決方案語法錯誤sqlite的內部連接

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 != ? 

請檢查一下,並告訴我一個對方付費的語法。感謝收看:) )))

回答

2

JOIN和表1名稱之間沒有空格(「」)。表名和表之間還有額外的空間。列名

修改成:

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

我想你會被罰款。

希望這會有所幫助。

+0

很高興我能幫忙:) @ user3001046 –