String TABLE_NAME = "WORD";
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME +
"(WORD TEXT, DEFINITION TEXT, DAY TEXT)");
//find out if we have entered data already
ContentValues cv = new ContentValues();
cv.put("WORD", "nuttin");
cv.put("DEFINITION", "nuttin");
cv.put("DAY", "nuttin");
db.insert("WORD", null, cv );
ContentValues cvUpdates = new ContentValues();
cvUpdates.put("WORD", " ");
cvUpdates.put("DEFINITION", " ");
cvUpdates.put("DAY", " ");
db.update("WORD", cvUpdates, null, null);
}
Why do I keep getting
sqlite> select * from word;
||
beating my head against the wall on this one…
There is a problem with the SQL-string you’re building to create your tables:
This will create:
You can see that it’s missing a white-space between the table-name and the fields (
... WORD( ...).If you have a look at your LogCat output, you might notice that the
execSQL()-method throws anSQLExceptiontelling you that the SQL-String is invalid. You should always catch those Exceptions!Just for the sake of completeness: The
SQLException-class extendsRuntimeException, which is an unchecked exception. More on this can be found here.