我想将songDetails表中的值复制到playlistDetails表。
这是我的代码:
public void transferData(String name) {
SQLiteDatabase db = this.getWritableDatabase();
String selectQuery = "INSERT INTO "+ TABLE_CURRENTLIST + " SELECT * FROM " + TABLE_DATA + " WHERE " + KEY_ALBUMNAME+ " = " + name + "";
db.execSQL(selectQuery);
}
执行此代码时,会抛出此异常
01-31 01:29:49.426: E/AndroidRuntime(3102): android.database.sqlite.SQLiteException: no such column: unknown (code 1): , while compiling: INSERT INTO PlayListDetails SELECT * FROM songDetails WHERE albumName = unknown
'name'变量的值是正确的。我想只复制albumName为unknown的行。 我很挣扎。请帮帮我。
答案 0 :(得分:1)
您缺少查询参数值(unknown
)周围的单引号。
您的查询应该是
String selectQuery = "INSERT INTO "+ TABLE_CURRENTLIST + " SELECT * FROM " + TABLE_DATA + " WHERE " + KEY_ALBUMNAME+ " = '" + name + "'";
我的建议是使用PreparedStatement样式参数。