问题描述
- 安卓出现这种sql错误是什么情况
-
package com.example.testdb.dos;import com.example.testdb.testdatabase;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;public class personDos {
private testdatabase helper;public personDos(Context context) { helper = new testdatabase(context); } public void add(String name,String number){ SQLiteDatabase db = helper.getWritableDatabase(); db.execSQL("insert into person(name,number) values (?,?)", new Object[](name,number)); db.close(); }
}
以上是全部代码Multiple markers at this line - The constructor Object(String, String) is undefined - The method execSQL(String, Object[]) in the type SQLiteDatabase is not applicable for the arguments (String, Object) - Syntax error on token(s), misplaced construct(s) 这是报的错误
解决方案
db.execSQL("insert into person(name,number) values (?,?)", new Object[](name,number));
改成
db.execSQL("insert into person(name,number) values (?,?)", new Object[]{name,number}); 是大括号
时间: 2024-09-18 07:01:44