0

my logcat message:

(1) near "INTEGER" : syntax error Exception in CREATE_SQL android.database.sqlite.SQLiteException: near "INTEGER" : syntax error (codee1): , while compiling: create BOMUL_PLACE( _id INTEGER NOT NULL PRIMARY KEY AUTOICREMENT, NAME TEXT, LAT DOUBLE, LNG DOUBLE, CHECK INTEGER DEFAULT 0);

and my code :

public void onCreate(SQLiteDatabase db) { //TABLE_BOMUL_PLACE println("creating table [" + TABLE_BOMUL_PLACE + "].");

       //drop existing table
       String DROP_SQL = "drop table if exists " + TABLE_BOMUL_PLACE;
       try
       {
           db.execSQL(DROP_SQL);
       }
       catch(Exception ex)
       {
           Log.e(TAG, "Exception in DROP_SQL", ex);
       }


       String CREATE_SQL = "create table " +  TABLE_BOMUL_PLACE + "("
               + "  _id INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT, "
               + "  NAME TEXT, "
               + "  LAT DOUBLE, "
               + "  LNG DOUBLE, "
               + "  CHECK INTEGER DEFAULT 0);";

       try 
       {
           db.execSQL(CREATE_SQL);
       } 
       catch(Exception ex) 
       {
           Log.e(TAG, "Exception in CREATE_SQL", ex);
       }

2 Answers 2

1

The syntax error is from the CHECK column. CHECK is an SQL reserved word and needs to be renamed or "quoted".

Other syntax problems from the logcat that you seem to have resolved in the code:

create BOMUL_PLACE( _id INTEGER NOT NULL PRIMARY KEY AUTOICREMENT, NAME TEXT, LAT DOUBLE, LNG DOUBLE, CHECK INTEGER DEFAULT 0
  • CREATE TABLE, TABLE missing

  • AUTOINCREMENT misspelled

  • ) missing at the end

Also, NOT NULL is redundant for a primary key column.

After fixing the onCreate(), uninstall your app so the previous database file gets deleted and onCreate() is called again. Catching exceptions is not recommended as SQLiteOpenHelper will think that the creation succeeded if onCreate() returns normally.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks laalto your advice worked. "check" was problem
-1

You can try to add space between table name TABLE_BOMUL_PLACE and ( symbol.

it should be 
TABLE_BOMUL_PLACE + " ("

1 Comment

try to rename column name check. It is keyword in SQLIte.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.