Db.execsql (SQL); or Db.insert (), Db.delete (), Db.update (), and including the creation and deletion of data tables, etc. can also be achieved through EXECSQL
Create a table
The code is as follows |
|
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
The code is as follows |
|
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
The code is as follows |
|
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; } |
}