为什么使用SQLite无法插入数据和创建表
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
public class SqlHelp extends SQLiteOpenHelper{
String createUserTable = "create table user_info(_id int auto_increment,username char(20),"
+ "password char(20),num char(20),primary key('_id'));";
String createUserTable2 = "create table user_info1(_id int auto_increment,username char(20),"
+ "password char(20),num char(20),primary key('_id'));";
String insertStr = "insert into user_info(_id,username,password,num) values(?,?,?,?);";
public SqlHelp(Context context, String name, CursorFactory factory, int version)
{
super(context, name, factory, version);
// TODO 自动生成的构造函数存根
}
@Override
public void onCreate(SQLiteDatabase arg0)
{
// TODO 自动生成的方法存根
int _id = 0;
arg0.execSQL(createUserTable);
arg0.execSQL(createUserTable2);
String[] insertValue = { "1", "hx", "123", "002", };
arg0.execSQL(insertStr, insertValue);
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
// TODO 自动生成的方法存根
}
}
使用这种方式插入和创建均不成功 在protected void onCreate(Bundle savedInstanceState)
使用sDatabase.execSQL("insert into user_info(_id,username,password,num) values(0,'hxx',123,001);");则可以 求解