Home > php教程 > php手册 > php SQLite增删改减实现代码

php SQLite增删改减实现代码

WBOY
Release: 2016-06-13 10:08:23
Original
1080 people have browsed it

db.execsql(sql); 或者db.insert()、db.delete()、db.update(),并且包括数据表的创建和删除等等也可以通过execsql实现
//创建表

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;
}

}

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template