0

我正在制作一个 sqlite 数据库表,并尝试在点击事件时更新我的​​数据库

SQLiteDatabase sd= openOrCreateDatabase("mynotedb", MODE_PRIVATE, null);
String sql  ="create table if not exists notecont(title nvarchar(70), description text)";
sd.execSQL(sql);
sd.close();

我正在运行以下更新命令,它显示了一个 sqlite 异常

 SQLiteDatabase db = openOrCreateDatabase("mynotedb", MODE_PRIVATE, null);
 String sql="";
 sql = "update notecont set title='"+et2.getText().toString()+"', " +"description='"+et1.getText().toString()+"' where title='"+et2.getText().toString()+"'";
 db.execSQL(sql);
 db.close();

以下的堆栈跟踪是:

android.database.sqlite.SQLiteException: near "s": syntax error (code 1): , while compiling: update notecont set title='tcs', description='1. what are the it services demand in fiscal 2014 ?

2. how much demand is coming for new services that account technology trends such as social media, mobility and big data ? and what is TCS doing in this regard ?

3. what's the progress TCS has made in cloud computing as TCS is having the biggest success in 2010 i.e from unisys corp.

4. what challenges TCS is facing in Indian it market ? 
' where title='tcs'
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1672)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1603)
at bitcream.my.notepad.Newnote.update(Newnote.java:211)
at bitcream.my.notepad.Newnote.checkempty(Newnote.java:386)
at bitcream.my.notepad.Newnote.access$0(Newnote.java:370)
at bitcream.my.notepad.Newnote$2.onClick(Newnote.java:103)
at android.view.View.performClick(View.java:4456)
at android.view.View$PerformClick.run(View.java:18465)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

请建议我修复。当我添加太多文本并执行更新查询时,它会触发我一个 sqlite 错误。提前致谢。

4

1 回答 1

1

要更新表中的行,请使用ContentValues

    ContentValues values = new ContentValues();
    values.put("title", et2.getText().toString());
    values.put("description", et1.getText().toString());

    db.update("notecont", values, "title = ?", new String[] { et2.getText().toString() });
于 2014-08-22T17:05:31.373 回答