1.
Package com.exp.contentprividerstest.db;
Import Android.content.Context;
Import Android.database.sqlite.SQLiteDatabase;
Import Android.database.sqlite.SQLiteOpenHelper;
public class Dburil extends Sqliteopenhelper {
public dburil (context context) {
& nbsp; super (context, "user.db", NULL, 2);
System.out.println ("Asdfasdfds");
}
@Override
public void OnCreate (Sqlitedatabase db) {
string sql= "CREATE TABLE User (ID int,name varchar (32))";
system.out.println (SQL);
db.execsql (SQL);
}
@Override
public void Onupgrade (sqlitedatabase arg0, int arg1, int ARG2) {
}
}
2.
Package com.exp.contentprividerstest.test;
Import Com.exp.contentprividerstest.db.DBUril;
Import android.content.ContentValues;
Import Android.database.Cursor;
Import Android.database.sqlite.SQLiteDatabase;
Import Android.test.AndroidTestCase;
public class DBTest extends androidtestcase{
public void Testinsert () {
Dburil dburil=new Dburil (GetContext ());
Sqlitedatabase database=dburil.getreadabledatabase ();
for (int i=0;i<10;i++) {
Contentvalues values=new contentvalues ();
Values.put ("id", i);
Values.put ("name", "name1:" +i);
Database.insert ("user", null, values);
}
}
public void Insert1 () {
Dburil dburil=new Dburil (GetContext ());
Sqlitedatabase database=dburil.getreadabledatabase ();
for (int i=0;i<10;i++) {
String []bindargs={"+i", "name1000" +i};
Database.execsql ("INSERT into user values (?,?)", Bindargs);
}
}
public void Delete () {
Dburil dburil=new Dburil (GetContext ());
Sqlitedatabase database=dburil.getreadabledatabase ();
Database.delete ("User", "id=?", New string[]{"4"});
}
public void Delete1 () {
Dburil dburil=new Dburil (GetContext ());
Sqlitedatabase database=dburil.getreadabledatabase ();
Database.delete ("User", "id=?", New string[]{"4"});
String sql= "Delete from user where id=?";
String bindargs[]={"10003"};
Database.execsql (SQL, Bindargs);
}
public void Update () {
Dburil dburil=new Dburil (GetContext ());
Sqlitedatabase database=dburil.getreadabledatabase ();
Contentvalues values=new contentvalues ();
Values.put ("name", "name3:333333333333333333");
Database.update ("User", Values, "id=", New string[]{"3"});
}
public void Update1 () {
Dburil dburil=new Dburil (GetContext ());
Sqlitedatabase database=dburil.getreadabledatabase ();
String sql= "Update user set name=?" where id=? ";
String bindargs[]={"1000000000000", "1003"};
Database.execsql (SQL, Bindargs);
}
public void query () {
Dburil dburil=new Dburil (GetContext ());
Sqlitedatabase database=dburil.getreadabledatabase ();
Cursor cursor=database.query ("user", NULL, NULL, NULL, NULL, NULL, NULL);
while (Cursor.movetonext ()) {
int Id=cursor.getint (CURSOR.GETCOLUMNINDEX ("id"));
String name=cursor.getstring (Cursor.getcolumnindex ("name"));
System.out.println (id+ "=" +name);
}
}
public void Query1 () {
Dburil dburil=new Dburil (GetContext ());
Sqlitedatabase database=dburil.getreadabledatabase ();
String sql= "SELECT * from user where id=?";
Cursor cursor=database.rawquery (SQL, New string[]{"10009"});
while (Cursor.movetonext ()) {
int Id=cursor.getint (CURSOR.GETCOLUMNINDEX ("id"));
String name=cursor.getstring (Cursor.getcolumnindex ("name"));
System.out.println (id+ "=" +name);
}
}
}
Android Operation SQLite Database