饭宝宝
2016-12-08 23:24
public void click(View view){
switch (view.getId()){
case R.id.btn_insert:
SQLiteDatabase db=sql.getWritableDatabase();
String sql1="insert into "+ Costant.TABLE_NAME+"values(1,'张三',20) ";
Dbmanager.execSQL(db,sql1);
String sql2="insert into "+ Costant.TABLE_NAME+"values(2,'lisi',21) ";
Dbmanager.execSQL(db,sql2);
db.close();
break;
}
}
我也是执行了插入语句,结果没有插入成功。而且跑飞了!
switch (view.getId()){
case R.id.btn_insert:
SQLiteDatabase db=mhelper.getWritableDatabase();
String sql="insert into person values(1,'zhangsan',20)";
DbManger.execSQL(db,sql);
String sql2="insert into "+
Constant_changlianglei.TABLE_NAME+
"values(2,'lisi',25)";
DbManger.execSQL(db,sql2);
db.close();
break;
报的为调用目标异常:
Caused by: java.lang.reflect.InvocationTargetException
SQLiteDatabase db=sql.getWritableDatabase();这句明显错了,把视频都看完的话会知道我们是新建了一个helper类用来拿到数据库,把这里的sql改成helper应该就能跑起来了
Android基础-初识SQLite
22229 学习 · 38 问题
相似问题