2013-05-29 63 views
6

當我執行這個查詢我得到'android.database.sqlite.SQLiteException:沒有這樣的列'錯誤是什麼?android.database.sqlite.SQLiteException:沒有這樣的列

public Cursor Getupdate(String rid) throws SQLException 
     { 

Cursor m1Cursor = db.rawQuery("SELECT _id FROM Meeting where meet="+rid , null); 
    if (m1Cursor != null) {   
     if(m1Cursor.getCount() > 0) 
     { 

      m1Cursor.moveToFirst(); 
     } 
    } 
return m1Cursor; 
} 

logcat的

05-28 01:22:27.999: E/AndroidRuntime(1411): FATAL EXCEPTION: main 
05-28 01:22:27.999: E/AndroidRuntime(1411): android.database.sqlite.SQLiteException: no such column: ttyuhomk: , while compiling: SELECT _id FROM Meeting where meet=rage 

回答

24

對於字符串數據類型總是用這樣引號 ' 「+擺脫+」'」因爲RID是字符串你得到錯誤。

您應該使用+擺脫只有擺脫類型爲int。

+0

你救了我! thnxx親愛的! –

16

你需要使用單引號(')在Where子句檢查..喜歡

db.rawQuery("SELECT _id FROM Meeting where meet='"+rid+"'" , null); 
+0

WEL如圖所示。現在如果rid是一個int數據類型呢?我會把它寫爲「SELECT _id FROM Meeting where meet =」+ rid – user3833732

4

或者,更好的是,使用PreparedStatement和綁定你變量。它會逃避字符串和適合你的日期。它也會幫助解決SQL注入問題。

還有人不知道這件事嗎?

5

您也可以使用這樣的。

db.rawQuery("SELECT _id FROM Meeting where meet=?" , 
      new String [] {rid}); 

這也將解決SQL注入的問題。

+1

'?'參數很好,只是沒有超過'String.valueOf(String)' – laalto

+1

哦!抱歉。實際上,它好像是這樣的db.rawQuery(「SELECT _id FROM Meeting where meet =?」,new String [] {rid});感謝您指出我的代碼。 –

+0

很棒的回答。只需要一些解釋,說明它如何幫助解決SQL注入問題。 – VVB

相關問題