通常在出现此问题时,由于缺少引号。但是这个专栏是INTEGER,我试图在其中加一个整数值。但是这个错误突然出现了:
android.database.sqlite.SQLiteException: no such column: 1 (code 1): , while compiling: INSERT INTO Artista (id, nome) VALUES (1, '19')
我的代码:
String CREATE_TABLE_ORIGEM =
"CREATE TABLE Origem" +
"(" +
"id INTEGER PRIMARY KEY, " +
"nome TEXT" +
")";
String CREATE_TABLE_ARTISTA =
"CREATE TABLE Artista" +
"(" +
"id INTEGER PRIMARY KEY, " +
"nome TEXT" +
")";
db.execSQL(CREATE_TABLE_ORIGEM);
db.execSQL(CREATE_TABLE_ARTISTA);
String INSERT_ORIGEM = "INSERT INTO Origem (id, nome)";
String INSERT_ARTISTA = "INSERT INTO Artista (id, nome)";
String line;
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(myContext.getAssets().open("origem.txt"), "UTF-8"));
try {
while ((line = reader.readLine()) != null)
db.execSQL(INSERT_ORIGEM + " VALUES (" + line + ")");
} catch(Exception e) {
throw new RuntimeException(e);
} finally {
reader.close();
}
reader = new BufferedReader(new InputStreamReader(myContext.getAssets().open("artista.txt"), "UTF-8"));
try {
while ((line = reader.readLine()) != null)
db.execSQL(INSERT_ARTISTA + " VALUES (" + line + ")");
} catch(Exception e) {
throw new RuntimeException(e);
} finally {
reader.close();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
这些是我用来填充表格的内容:
origem.txt:http://pastebin.com/Vk2wHnm5
artista.txt:http://pastebin.com/wfWSbvfR
答案 0 :(得分:1)
您的文本文件在开头包含一个不可见的控制字符(可能是UTF-8字节顺序标记)。删除它。
答案 1 :(得分:0)
简而言之,如果您随着时间的推移进行了DDL更改,那么您可能正在使用比您意识到的旧版本的架构:
希望这在某种程度上有所帮助。
答案 2 :(得分:-1)
您可以尝试直接从AVD或Real设备清理您的应用数据,以“更新”您的表格。