Skip to content Skip to sidebar Skip to footer

SQLiteException Near "null": Syntax Error: , While Compiling: INSERT OR REPLACE INTO

I am trying to configure a simple DbHelper, and getting an error while executing. The error is: SQLiteException near 'null': syntax error: , while compiling: INSERT OR REPLACE INT

Solution 1:

You need to put in the values before you do the insert, not after, otherwise you're not inserting anything. Change this:

ContentValues values = new ContentValues();
db.insertWithOnConflict(DbHelper.DB_TABLE, null, values,
        SQLiteDatabase.CONFLICT_REPLACE);
values.put(DbHelper.C_DATE, variable1);

to this:

ContentValues values = new ContentValues();
values.put(DbHelper.C_DATE, variable1);
db.insertWithOnConflict(DbHelper.DB_TABLE, null, values,
        SQLiteDatabase.CONFLICT_REPLACE);

EDIT

Found another issue:

db.execSQL("create table if not exists " + DB_TABLE + " (" + C_ID + "integer primary key autoincrement, " + C_DATE + " text not null );");

The above code is creating a primary key called iderty_idinteger. It should be like this:

db.execSQL("create table if not exists " + DB_TABLE + " (" + C_ID + " integer primary key autoincrement, " + C_DATE + " text not null );");

Note the space inserted before integer primary...


Post a Comment for "SQLiteException Near "null": Syntax Error: , While Compiling: INSERT OR REPLACE INTO"