时间:2021-07-01 10:21:17 帮助过:18人阅读
public boolean createtable(){
sqlitedatabase db=dbhelper.getwritabledatabase();
string sql="create table if not exists "+table_name+"(id integer primary key,name varchar,age integer)";
try{
db.execsql(sql);
return true;
}catch(sqlexception ex){
log.d(tag, "create table failure");
return false;
}
}
//添加数据
public boolean adddata(){
string name=etname.gettext().tostring();
string age=etage.gettext().tostring();
sqlitedatabase db=dbhelper.getwritabledatabase();
string sql="insert into "+table_name+"(name,age) values ('"+name+"','"+age+"')";
try{
db.execsql(sql);
return true;
}catch(sqlexception ex){
log.d(tag, "add data failure");
return false;
}
}
//修改
public boolean updatedata(){
sqlitedatabase db=dbhelper.getwritabledatabase();
string sql="update "+table_name+" set age='2' where name like 'cb'";
object[] bindargs={"cb"};
try{
db.execsql(sql, bindargs);
return true;
}catch(sqlexception ex){
log.d(tag, "update data failure");
return false;
}
}
http://www.bkjia.com/PHPjc/630782.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630782.htmlTechArticledb.execsql(sql); 或者db.insert()、db.delete()、db.update(),并且包括数据表的创建和删除等等也可以通过execsql实现 //创建表 public boolean createtable(){...