1

I have this code:

      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);

Where LAST_OPEN field is timestamp.I tried to run the same query in SQlite Browser it was working fine.But when this Sql is executed in app it shows this:

       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)

Can anyone tell where I am getting wrong?

2 Answers 2

1

Try with this sql statement :

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

as I know, when you are using any string data in sql statement you need to add '' in the beginning of the variable and at the end of it.

Sign up to request clarification or add additional context in comments.

Comments

1

Try to change

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

with

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

The space between the numbers can be the problem. Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.