gpt4 book ai didi

android - 更新时间戳时出现 Sqliteexception?

转载 作者:行者123 更新时间:2023-11-29 22:12:40 28 4
gpt4 key购买 nike

我有这个代码:

      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 字段是时间戳的地方。我试图在 SQlite 浏览器中运行相同的查询,它工作正常。但是当这个 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)

谁能告诉我哪里出错了?

最佳答案

试试这个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 语句中使用任何字符串数据时,您需要在变量的开头和结尾添加 ''

关于android - 更新时间戳时出现 Sqliteexception?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9257133/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com