gpt4 book ai didi

java - SQLite异常: no such column: 1 (code 1):

转载 作者:太空宇宙 更新时间:2023-11-04 12:26:52 25 4
gpt4 key购买 nike

通常,当出现此问题时,是因为缺少引号。但此列是 INTEGER,我试图在其中放入一个整数值。但弹出此错误:

android.database.sqlite.SQLiteException:没有这样的列:1(代码1):,编译时: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
艺术家.txt:http://pastebin.com/wfWSbvfR

有趣的是:Origem 表具有相同的格式,但我没有发现任何错误;

最佳答案

您的文本文件在开头包含一个不可见的控制字符(可能是 UTF-8 字节顺序标记)。删除它。

关于java - SQLite异常: no such column: 1 (code 1):,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38287668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com