I use the following code to insert data into a table
SQLiteDatabase db = this.getWritableDatabase();
String CREATE_FOLLOWING_TABLE = "CREATE TABLE IF NOT EXISTS " + FOLLOWING_TABLE_NAME + "("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_USER_ID + " TEXT)";
db.execSQL("DROP TABLE IF EXISTS " + FOLLOWING_TABLE_NAME);
db.execSQL(CREATE_FOLLOWING_TABLE);
String sql = "INSERT INTO " + FOLLOWING_TABLE_NAME + " (" + KEY_USER_ID + ") VALUES(?)";
db.beginTransaction();
SQLiteStatement stmt = db.compileStatement(sql);
for(String id : userIds) { // userIds is ArrayList<String>
stmt.bindString(1, id);
stmt.execute();
stmt.clearBindings();
}
db.setTransactionSuccessful();
db.endTransaction();
db.close();
I confirmed that the userIds ArrayList
contains String
values which are like qWz17mh. However, after running the above code, I get the following in the table
_id userid
1 1
2 2
3 3
4 4
5 5
6 6
I don't know why this is happening. My suspicion lies in the insert syntax. What do you think is wrong? Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire