我有一个由baseadapter从数据库填充的StaggeredGridView。我想更新一行(一个单元格)的内容。但是我收到了这个错误:
android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: UPDATE ASSIS_NOTES_TABLE SET =?,ffhj=?,dfhj=? WHERE Assis_Note_Title=dfhj
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.updateWithOnConflict(SQLiteDatabase.java:1572)
at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1520)
at com.hirak.assistere_doit.tasks_Database_Operations.updatenote(tasks_Database_Operations.java:68)
at com.hirak.assistere_doit.edit_note_frag.onClick(edit_note_frag.java:81)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
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:5001)
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)
以下是我的代码:
具有gridview的片段:(在列表项目上单击,另一个片段打开,用户编辑文本(这里一切都很好)
notesSGV.setOnItemClickListener(new StaggeredGridView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String edit_title = ((TextView)view.findViewById(R.id.note_title_added)).getText().toString();
String edit_note = ((TextView)view.findViewById(R.id.notes_grid_text)).getText().toString();
String color = ((TextView)view.findViewById(R.id.color)).getText().toString();
edit_note_frag editNoteFrag = new edit_note_frag();
Bundle b = new Bundle();
b.putString("title", edit_title);
b.putString("note", edit_note);
b.putString("color", color);
editNoteFrag.setArguments(b);
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.addToBackStack("eNF");
ft.setCustomAnimations(R.anim.slide_up, R.anim.slide_down);
ft.replace(R.id.MainContent, editNoteFrag, "eNF");
ft.commit();
}
});
用户更新项目的片段:
@Override
public void onResume() {
super.onResume();
title = getArguments().getString("title");
note = getArguments().getString("note");
color = getArguments().getString("color");
iii = getArguments().getInt("id");
edit_note.setText(note);
edit_title.setText(title);
然后在按钮上单击相同的片段,将调用更新:
@Override
public void onClick(View v) {
if (v == update){
final tasks_Database_Operations tasksDatabaseOperations = new tasks_Database_Operations(getActivity());
tasksDatabaseOperations.getWritableDatabase();
tasksDatabaseOperations.updatenote(iii, title, note, color);
tasksDatabaseOperations.close();
Toast.makeText(getActivity(), title, Toast.LENGTH_SHORT).show();
}
}
这是数据库类&#34;
中的更新查询 public void updatenote(int id, String title, String note, String color) {
this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(title, ASSIS_NOTES_TITLE);
contentValues.put(note, ASSIS_NOTES);
contentValues.put(color, ASSIS_NOTES_COLOR);
sqLiteDatabase.update(ASSIS_NOTES_TABLE_NAME, contentValues, ASSIS_NOTES_TITLE + "=" + title , null);
sqLiteDatabase.close();
}
答案 0 :(得分:1)
请更改您的代码并尝试此操作,希望它能为您提供帮助。
sqLiteDatabase.update(ASSIS_NOTES_TABLE_NAME, contentValues, ASSIS_NOTES_TITLE+"='" + title + "'", null);
答案 1 :(得分:0)
从错误日志中删除查询中的第一个列名称
UPDATE ASSIS_NOTES_TABLE SET =?,ffhj=?,dfhj=? WHERE Assis_Note_Title=dfhj
这就是为什么在near "="
UPDATE ASSIS_NOTES_TABLE SET First=?,Second=?,Third=? WHERE Assis_Note_Title=dfhj
等等。