Android SQLite没有这样的表?

时间:2013-02-11 17:32:36

标签: android sql database sqlite

我创建了一个方法

public boolean addWord(Word w, String name) {
    try {
        ContentValues cv = new ContentValues();
        cv.put(COLUMN_NAME, name);
        cv.put(COLUMN_WORD_FOREIGN, w.getWordForeign());
        cv.put(COLUMN_WORD_ENGLISH, w.getWordEnglish());
        cv.put(COLUMN_CORRECT, w.getCorrect());
        database.insert(TABLE_VOCAB_WORDS, null, cv);
        return true;
    } catch (SQLiteException e) {
        System.out.println("SQL ERROR");
        return false;
    }
}

但每当我调用它时,我都会找到一个找不到表的错误。但是,我用于创建数据库的SQL语句如下:

private static final String CREATE_DB = "CREATE TABLE " + TABLE_VOCAB_INFO
        + "(" + COLUMN_NAME + " TEXT NOT NULL PRIMARY KEY," + COLUMN_URL
        + " TEXT NOT NULL," + COLUMN_DOWNLOADED
        + " TEXT NOT NULL); CREATE TABLE " + TABLE_VOCAB_WORDS + "("
        + COLUMN_NAME + " TEXT NOT NULL," + COLUMN_WORD_FOREIGN
        + " TEXT NOT NULL," + COLUMN_WORD_ENGLISH + " TEXT NOT NULL,"
        + COLUMN_CORRECT + " BYTE NOT NULL, PRIMARY KEY (" + COLUMN_NAME
        + "," + COLUMN_WORD_FOREIGN + "));";

由于我正在创建表格,我不太确定实际发生了什么错误  这里吗?

有什么建议吗?

1 个答案:

答案 0 :(得分:3)

我认为这不起作用的原因是;这个字符是不被允许的。因此,尝试使用两个分开的Strings来执行此操作:

String create_vocal_table_info_query = "CREATE TABLE " + TABLE_VOCAB_INFO
        + "(" + COLUMN_NAME + " TEXT NOT NULL PRIMARY KEY,"
        + COLUMN_URL + " TEXT NOT NULL,"
        + COLUMN_DOWNLOADED + " TEXT NOT NULL)";

String create_vocal_table_words_query = "CREATE TABLE " + TABLE_VOCAB_WORDS + "("
        + COLUMN_NAME + " TEXT NOT NULL,"
        + COLUMN_WORD_FOREIGN + " TEXT NOT NULL,"
        + COLUMN_WORD_ENGLISH + " TEXT NOT NULL,"
        + COLUMN_CORRECT + " BYTE NOT NULL, PRIMARY KEY ("
        + COLUMN_NAME + "," + COLUMN_WORD_FOREIGN + "))";