Reputation: 745
I have created a method
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;
}
}
But whenever I call it, I am getting a table not found error. However, the SQL statement that I use to create the database is as follows :
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 + "));";
As I am clearly creating the table, I'm not quite sure what error is actually happening here?
Any suggestions?
Upvotes: 0
Views: 1505
Reputation: 33515
I think reason why this not working is ;
This char is not allowed. So try to do it with two separated Strings
so:
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 + "))";
Upvotes: 3