Android:Sqlite插入硬编码数据

时间:2012-06-15 08:49:15

标签: android sqlite

我在表格中插入了两个字段,即truck_id和employee_id。

很抱歉提出这个问题。但由于我是Android的新手,请帮助我。

public void insert(String[] employeeName,int[] truck_id){

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues vals = new ContentValues();

    vals.put(COLUMN_TRUCKID, "CM-3456");
    vals.put(COLUMN_NAME,"Sachin");
    //vals.put(KEY_PIN, "12345");

    vals.put(COLUMN_TRUCKID, "HR-6788");
    vals.put(COLUMN_NAME,"Sameer");
    //vals.put(KEY_PIN, "54321");

    vals.put(COLUMN_ID, "AM-6123");
    vals.put(COLUMN_NAME,"Sahu");
    //vals.put(KEY_PIN, "3452");

    db.insert("Login", "John",
            vals);
    db.insert("Login", "Sameer",
            vals);

    db.execSQL(COLUMN_NAME);

    //myDataBase.close();
}

1 个答案:

答案 0 :(得分:0)

ContentValuesMap,因此每个列名一次只能包含一个条目。因此,您需要在设置其值后单独插入每个项目。

vals.put(COLUMN_TRUCKID, "CM-3456");
vals.put(COLUMN_NAME,"Sachin");
db.insert("Login", null, vals);

vals.put(COLUMN_TRUCKID, "HR-6788");
vals.put(COLUMN_NAME,"Sameer");
db.insert("Login", null, vals);

删除此行,否则会发生不好的事情:

db.execSQL(COLUMN_NAME);