0

我创建了一个方法

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 + "));";

当我清楚地创建表格时,我不太确定这里实际发生了什么错误?

有什么建议么?

4

1 回答 1

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 + "))";
于 2013-02-11T17:57:17.813 回答