Android SQLite INSERT

I am using execSQL on SQLite database. The sql INSERT strnig is

INSERT INTO Tasks 
(_id, Aircraft, Station, Discrepancy,DateCreated, CreatedBy, Status, DateClosed, ClosedBy, ArrivalFlightID, RecordChangedByUI)  
 VALUES 
('271104','   ','ORD','Critical Flight (0496/28)','9/4/2011 6:57:00 PM','SYSTEM','NEW','','null','0','N')

Table is

  • Programming my android application with Gimbal sdk doesn't detect the gimbal beacon
  • Send APDU commands to USIM/SIM card in android
  • How do I create an android Intent that carries data?
  • Fail to find annotations.jar after updating to ADT 23
  • How to play a video with the YouTube API using YouTubePlayerFragment?
  • android - listview filter count
  • "create table Tasks 
    (_id integer primary key, "
    + "Aircraft text null, Station text null, Discrepancy text null, DateCreated text null, CreatedBy text null, Status text null, DateClosed text, ClosedBy text null, ArrivalFlightID text null, RecordChangedByUI text null);";
    

    It’s throwing an exception “Empty bindArgs”

    Can anybody tell me where I am going wrong ?

    Related posts:

    Can you center a Button in RelativeLayout?
    Difference between LocationRequest setInterval (long millis) and LocationRequest setFastestInterval ...
    failure : retrofit.RetrofitError: 307 Temporary Redirect?
    How to set tint for an image view programmatically in android?
    Android: RecyclerView item when set to clickable blocks onTouch events
    Lock the android orientation as landscape throughout the App?
  • How to prevent Android's drawBitmap from only drawing black images?
  • What is the purpose of requestWindowFeature()?
  • How does application install size vary on phone?
  • Android runOnUiThread explanation
  • How to transfer a SIP call using the built in android SIP stack
  • How to run custom rule in Android.mk before compilation?
  • 2 Solutions collect form web for “Android SQLite INSERT”

    You can not pass null as second parameter. If you’re not using it, just ignore it and it will work:

    String sql = "INSERT INTO Tasks (_id, Aircraft, Station, Discrepancy,DateCreated, CreatedBy, Status, DateClosed, ClosedBy, ArrivalFlightID, RecordChangedByUI) " VALUES ('" + tasks[i]._id + "','" + tasks[i].Aircraft + "','" + tasks[i].Station + "','" + tasks[i].Discrepancy + "','" + tasks[i].DateCreated + "','" + tasks[i].CreatedBy + "','" + tasks[i].Status + "','" + tasks[i].DateClosed + "','" + tasks[i].ClosedBy + "','" + tasks[i].ArrivalFlightID + "','N')"; 
    this.database.execSQL(sql); 
    

    However, the above example is vulnerable – SQL query can be easily injected. All strings passed to the query should be escaped via DatabaseUtils.sqlEscapeString(task[i].something).

    Try executing database.insert or insertOrThrow. It requires the explicit adding of each field to a ContentValues object, but it is so much neater.

    ContentValues insertValues = new ContentValues();
    insertValues.put("_id", tasks[i]._id);
    ... // other fields
    long rowId = this.database.insert(DATABASE_TABLE, null, insertValues);
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.