gpt4 book ai didi

android - 向数据库中插入两条或多条数据

转载 作者:行者123 更新时间:2023-11-30 00:56:22 26 4
gpt4 key购买 nike

我想向数据库中插入两条或更多条数据,但行不通。这是我的 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();
}
}

关于如何解决这个问题有什么建议吗?

最佳答案

将您的 CreateTable 查询更改为:

 String CreateTABLE="CREATE TABLE IF NOT EXISTS " +
TABLE_NAME + " (" +
COL1_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COL2_Barcode + " TEXT, " +
COL3_Time + " TEXT)";

您似乎忘记了查询中的逗号。

关于android - 向数据库中插入两条或多条数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40092799/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com