我想将两个或多个数据插入数据库,但它不起作用。这是我的Databasehelper
课程:
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String CreateTABLE="CREATE TABLE IF NOT EXISTS " +
TABLE_NAME + " (" +
COL1_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COL2_Barcode + " TEXT" +
COL3_Time + " TEXT)";
sqLiteDatabase.execSQL(CreateTABLE);
}
public boolean insertData(String barcodecontent, String systemtime) {
db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL2_Barcode, barcodecontent);
contentValues.put(COL3_Time, systemtime);
long result = db.insert(TABLE_NAME,null, contentValues);
if(result == -1)
return false;
else
return true;
}
这是我的IncomingActivity
课程:
public void AddData() {
boolean isInserted = myDB.insertData(incoming_brc_textview.getText().toString(), incoming_hide_time.getText().toString());
if (isInserted == true) {
Toast.makeText(IncomingActivity.this, incoming_brc_textview.getText().toString() + " store success", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(IncomingActivity.this, incoming_brc_textview.getText().toString() + " store failure", Toast.LENGTH_LONG).show();
}
}
有关如何解决此问题的任何建议?
答案 0 :(得分:1)
将您的CreateTable
查询更改为:
String CreateTABLE="CREATE TABLE IF NOT EXISTS " +
TABLE_NAME + " (" +
COL1_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COL2_Barcode + " TEXT, " +
COL3_Time + " TEXT)";
您的查询中似乎忘记了逗号。