gpt4 book ai didi

Java SQLite execSQL 语法错误

转载 作者:行者123 更新时间:2023-12-02 05:25:23 27 4
gpt4 key购买 nike

我的 android 项目中有以下 execSQL,它抛出语法错误并导致我的应用程序崩溃。我不明白为什么。

private static final String TABLE_QUESTIONS = "question";
private static final String KEY_ID_Q = "id";
private static final String KEY_QUESTION_Q = "question";
private static final String KEY_ANSWER1_Q = "answer1";
private static final String KEY_ANSWER2_Q = "answer2";
private static final String KEY_ANSWER3_Q = "answer3";
private static final String KEY_ANSWER4_Q = "answer4";
private static final String KEY_TYPE_Q = "type_Q";
[... ]


String CREATE_QUESTIONS_TABLE = "CREATE TABLE " + TABLE_QUESTIONS + "("
+ KEY_ID_Q + " INTEGER PRIMARY KEY,"
+ KEY_QUESTION_Q + " TEXT,"
+ KEY_ANSWER1_Q + " INTEGER,"
+ KEY_ANSWER2_Q + " INTEGER,"
+ KEY_ANSWER3_Q + " INTEGER,"
+ KEY_ANSWER4_Q + " INTEGER,"
+ KEY_TYPE_Q + "INTEGER" + ")";
db.execSQL(CREATE_QUESTIONS_TABLE);
db.execSQL("INSERT INTO " + TABLE_QUESTIONS +" (" + KEY_QUESTION_Q + ", " + KEY_ANSWER1_Q + ", " + KEY_ANSWER2_Q+ ", " + KEY_ANSWER3_Q + ", " + KEY_ANSWER4_Q + ", " + KEY_TYPE_Q + ") VALUES (" + QUESTION[a] + ", "+(a*4+1)+", "+(a*4+2)+", "+(a*4+3)+", "+(a*4+4)+", "+q_type+");");

日志猫:

    09-28 21:27:26.629: E/Database(1070): Failure 1 (table question has no column named type_Q) on 0x2c3868 when preparing 'INSERT INTO question (question, answer1, answer2, answer3, answer4, type_Q) VALUES ('AnyString', 1, 2, 3, 4, 1);'.

我希望你们中的一些人能弄清楚:)

最佳答案

就像你忘记了一个空格一样简单;

+ KEY_TYPE_Q + "INTEGER" + ")";

应该是

+ KEY_TYPE_Q + " INTEGER" + ")";

...否则您将尝试创建一个名为 type_QINTEGER 且没有类型的字段。

关于Java SQLite execSQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26089977/

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