db.execsql(sql); or db.insert(), db.delete(), db.update(), and the creation and deletion of data tables, etc. can also be achieved through execsql
//Create table
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;
}
}
//Add data
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;
}
}
//Modify
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;
}
}