php SQLite addition, deletion, modification and subtraction implementation code_PHP tutorial

WBOY
Release: 2016-07-13 17:05:16
Original
1013 people have browsed it

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

}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630782.htmlTechArticledb.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(){...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template