problem with database_handler

0 Neera Pokhrel · September 12, 2015
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE" + TABLE_NAME + "(" +
COLUMN_ID + "INTEGER PRIMARY KEY AUTOINCREMENT," +
COLUMN_PRODUCT_NAME +"TEXT" +
");";
db.execSQL(query);
Error:
Caused by: android.database.sqlite.SQLiteException: near "TABLEitems": syntax error (code 1): , while compiling: CREATE TABLEitems(_idINTEGER PRIMARY KEY AUTOINCREMENT,_productNameTEXT);

Post a Reply

Replies

Oldest  Newest  Rating
+1 Milan Obrenovic · September 13, 2015
@Clark, semicolon has nothing to do with anything. SQL always lets you to either put the semicolon or not.

@Neera your problem is about spacing. The words in capital letters are SQL's keywords, and you can't merge them together with regular words. You wrote

"...colId1INTEGER PRIMARY KEY..."
"...colProdNameTEXT);"

instead of

"...colId1 INTEGER PRIMARY KEY..."
"colProdName TEXT);"

String query = "CREATE TABLE" + TABLE_NAME + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_PRODUCT_NAME + " TEXT " +
");";
0 Neera Pokhrel · September 15, 2015
Thanks a lot.. :)
  • 1

Java / Android Development

107,242 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator