当我尝试更新表时应用程序崩溃并返回此致命错误:
06-09 08:02:34.026: I/Database(342): sqlite returned: error code = 1, msg = no such column: username
06-09 08:02:34.034: E/Database(342): Error updating valore=1234 using UPDATE parametri SET valore=? WHERE _parametro=username
06-09 08:02:34.034: D/AndroidRuntime(342): Shutting down VM
06-09 08:02:34.034: W/dalvikvm(342): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-09 08:02:34.054: E/AndroidRuntime(342): FATAL EXCEPTION: main
06-09 08:02:34.054: E/AndroidRuntime(342): android.database.sqlite.SQLiteException: no such column: username: , while compiling: UPDATE parametri SET valore=? WHERE _parametro=username
插入/更新的功能是:
String strFilter = ParametriMetaData.PARAMETRO+"=" + parametro;
ContentValues args = new ContentValues();
args.put(ParametriMetaData.VALORE, valore);
System.out.println( strFilter );
mDb.update(ParametriMetaData.TAB_PARAMETRI, args, strFilter, null);
这是表的定义:
private static final String CREA_TAB_PARAMETRI = "CREATE TABLE IF NOT EXISTS " //codice sql di creazione della tabella
+ ParametriMetaData.TAB_PARAMETRI + " ("
+ ParametriMetaData.PARAMETRO+ " text primary key, "
+ ParametriMetaData.VALORE + " text not null);";
的WhatsUp?谢谢!
答案 0 :(得分:0)
更新查询必须具有适当的where子句update(tablename, value, referenceField+"=?", value);
String strFilter = ParametriMetaData.PARAMETRO+"=?";
ContentValues args = new ContentValues();
args.put(ParametriMetaData.VALORE, valore);
System.out.println( strFilter );
mDb.update(ParametriMetaData.TAB_PARAMETRI, args, strFilter, parametro);
答案 1 :(得分:0)
我会转到sqlite3(通过adb shell)并验证相关表是否有一个名为“username”的列。您可以使用schema ?TABLE?
查看SQL CREATE语句。我认为你的表结构会有问题。
通过在终端(unix)或命令提示符(窗口)中执行sqlite3
然后adb shell
来访问sqlite3
命令。 The documentation for sqlite3 can be found here.