2012-02-13 383 views
1

我有這樣的代碼:更新時間戳時Sqliteexception?

 String sql="UPDATE LAST_OPEN SET LAST_OPEN="+DATE+" WHERE STUDENT_ID ="+STUDENT_ID+" AND ITEM_ID="+ITEM_ID+" AND ITEM_NAME="+ITEM_TYPE+";"; 

db.execSQL(sql); 

哪裏LAST_OPEN場timestamp.I想跑SQLite中的瀏覽器,它正在fine.But相同的查詢時,該SQL應用程序中執行它顯示了這一點:

 02-13 13:12:39.468: E/AndroidRuntime(2366): FATAL EXCEPTION: main 
     02-13 13:12:39.468: E/AndroidRuntime(2366): android.database.sqlite.SQLiteException: near "13": syntax error: UPDATE LAST_OPEN SET LAST_OPEN=2012-02-13 13:12:39 WHERE STUDENT_ID =5 AND ITEM_ID=1 AND ITEM_NAME=Activity; 
     02-13 13:12:39.468: E/AndroidRuntime(2366): at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method) 
     -13 13:12:39.468: E/AndroidRuntime(2366): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1727) 
     02-13 13:12:39.468: E/AndroidRuntime(2366):  at com.cuelearn.databases.last_open.update(last_open.java:205) 
     02-13 13:12:39.468: E/AndroidRuntime(2366): at com.cuelearn.main.threeshelf$1.onClick(threeshelf.java:197) 
     02-13 13:12:39.468: E/AndroidRuntime(2366): at android.view.View.performClick(View.java:2408) 
     02-13 13:12:39.468: E/AndroidRuntime(2366): at android.view.View$PerformClick.run(View.java:8816) 
    02-13 13:12:39.468: E/AndroidRuntime(2366): at android.os.Handler.handleCallback(Handler.java:587) 
     02-13 13:12:39.468: E/AndroidRuntime(2366): at android.os.Handler.dispatchMessage(Handler.java:92) 
     02-13 13:12:39.468: E/AndroidRuntime(2366): at android.os.Looper.loop(Looper.java:123) 
    02-13 13:12:39.468: E/AndroidRuntime(2366): at android.app.ActivityThread.main(ActivityThread.java:4627) 
    02-13 13:12:39.468: E/AndroidRuntime(2366):  at java.lang.reflect.Method.invokeNative(Native Method) 
    02-13 13:12:39.468: E/AndroidRuntime(2366): at java.lang.reflect.Method.invoke(Method.java:521) 
     02-13 13:12:39.468: E/AndroidRuntime(2366): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
     02-13 13:12:39.468: E/AndroidRuntime(2366):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 

任何人都可以告訴我哪裏出錯了嗎?

回答

1

嘗試用這條SQL語句:

String sql="UPDATE LAST_OPEN SET LAST_OPEN='"+DATE+"' WHERE STUDENT_ID ="+STUDENT_ID+" AND ITEM_ID="+ITEM_ID+" AND ITEM_NAME="+ITEM_TYPE+";";

,因爲我知道,當您使用的是SQL語句中的任何字符串數據,你需要在變量的開頭,並在它的末尾添加''

+0

謝謝先生,這工作 – Navdroid 2012-02-13 08:14:16

+0

很高興聽到:) – 2012-02-13 08:24:57

1

嘗試改變

LAST_OPEN=2012-02-13 13:12:39 

LAST_OPEN = "2012-02-13 13:12:39" 

數字之間的空間可以是問題。希望這可以幫助。