Android 如何将二维码数据输入Sqlite表格?
嗨,我正在尝试将QR数据放入我的数据库表中。但当我扫描时,会出现以下错误: E/SQLiteDatabase:在“10”附近插入错误:语法错误(Sqlite代码1 Sqlite_错误):编译时:插入BSIT103_BSIT3(10/24,学生编号,姓名)值(?,,,?),(操作系统错误-11:重试) ClassDB:Android 如何将二维码数据输入Sqlite表格?,android,android-studio,android-sqlite,Android,Android Studio,Android Sqlite,嗨,我正在尝试将QR数据放入我的数据库表中。但当我扫描时,会出现以下错误: E/SQLiteDatabase:在“10”附近插入错误:语法错误(Sqlite代码1 Sqlite_错误):编译时:插入BSIT103_BSIT3(10/24,学生编号,姓名)值(?,,,?),(操作系统错误-11:重试) ClassDB: public boolean insertStudent(String type, String data, String data1){ SQLiteDatabase d
public boolean insertStudent(String type, String data, String data1){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
String student[] = type.split(":");
contentValues.put(COL_6, student[0]);
contentValues.put(COL_3, student[1]);
contentValues.put(data, student[2]);
long result = db.insert(data1,null,contentValues);
if(result == -1)
return false;
else
return true;
}
活动:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
Intent sIntent = getIntent();
ExampleClassInfo sClass = sIntent.getParcelableExtra("selected");
String selCode = sClass.getiCode();
String selDate = sClass.getiDate();
IntentResult result = IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
if (result != null)
{
if(result.getContents() == null){
Toast.makeText(this, "No Result Found", Toast.LENGTH_SHORT).show();
}else{
boolean isInserted = classDB.insertStudent(result.getContents(),selDate,selCode);
if(isInserted){
exampleClassArrayList.clear();
createClassList();
exampleClassArrayList = classDB.getAllInfromation2(selCode,selDate);
buildRecycleView();
}
}
} else {
super.onActivityResult(requestCode,resultCode,data);
}
}
自定义二维码数据:
例句:例句:例句
这一行:
db.insert(data1,null,contentValues);
将变量data1
的值插入到名为的表中,该行包含您分配给contentValues
的值您的表名是变量
data1
的值吗?此外,这一行:
contentValues.put(data, student[2]);
将变量数据的值分配给名为的列student[2]
。
这是列的正确名称吗?
我不这么认为,它应该有一个类似于COL_4
或类似于表中其他列的名称
您得到的错误点用作表名:BSIT103\u BSIT3
和列名:10/24
,这当然是不允许的(如果是列名),并且应该用方括号或倒勾括起来,因为它以数字开头,并且包含非法字符/
contentValues.put(数据,学生[2]);
-你为什么要用数据
来做钥匙呢?你不想用一些列*
来做吗?