1. sqlitehelper. Java: Create a database, Form
Package com. Android;
Import Android. content. context;
Import Android. database. SQLite. sqlitedatabase;
Import Android. database. SQLite. sqlitedatabase. cursorfactory;
Import Android. database. SQLite. sqliteopenhelper;
Public class SQLite extends sqliteopenhelper {
Public SQLite (context, string name, cursorfactory factory,
Int version ){
Super (context, name, factory, version );
}
@ Override
Public void oncreate (sqlitedatabase dB ){
System. Out. println ("create DB ");
Db.exe csql ("create table user (ID int, name varchar (15)"); // create a form
}
@ Override
Public void onupgrade (sqlitedatabase dB, int oldversion, int newversion ){
// Todo auto-generated method stub
}
}
2. sqliteactivity. Java: implement data operations, add, delete, modify, and query
Package com. Android;
Import Android. App. activity;
Import Android. content. contentvalues;
Import Android. database. cursor;
Import Android. database. SQLite. sqlitedatabase;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. widget. Button;
Public class sqlactivity extends activity {
Private button buttcreate;
Private button buttselect;
Private button buttinsert;
Private button buttupdate;
Private button buttdelete;
Public sqlitedatabase dB () {// create a database
SQLite dbhelper = new SQLite (sqlactivity. This, "test_sqlite ",
Null, 1 );
Sqlitedatabase DB = dbhelper. getreadabledatabase ();
Return dB;
}
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
// Space ID variable Declaration
Buttcreate = (button) This. findviewbyid (R. Id. buttcreate );
Buttselect = (button) This. findviewbyid (R. Id. buttselect );
Buttinsert = (button) This. findviewbyid (R. Id. buttinsert );
Buttupdate = (button) This. findviewbyid (R. Id. buttupdate );
Buttdelete = (button) This. findviewbyid (R. Id. buttdelete );;
Buttcreate. setonclicklistener (New View. onclicklistener () {// create a database
@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
DB ();
System. Out. println ("create database ");
}
});
This. buttselect. setonclicklistener (New View. onclicklistener () {// query
@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Sqlitedatabase DB = dB ();
Cursor cursor = dB. Query ("user", new string [] {"ID", "name"}, "id =? ", New string [] {" 1 "}, null );
While (cursor. movetonext ()){
String name = cursor. getstring (cursor. getcolumnindex ("name "));
System. Out. println ("name =" + name );
}
}
});
Buttinsert. setonclicklistener (New View. onclicklistener () {// Add
@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Contentvalues value = new contentvalues ();
Value. Put ("ID", 1 );
Value. Put ("name", "Che ");
Sqlitedatabase DB = dB ();
DB. insert ("user", null, value );
System. Out. println ("insert ---");
}
});
This. buttupdate. setonclicklistener (New View. onclicklistener () {// update
@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Sqlitedatabase DB = dB ();
Contentvalues value = new contentvalues ();
Value. Put ("name", "Cheche ");
DB. Update ("user", value, "id =? ", New string [] {" 1 "});
System. Out. println ("update ---");
}
});
This. buttdelete. setonclicklistener (New View. onclicklistener () {// Delete
@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Sqlitedatabase DB = dB ();
DB. Delete ("user", "name =? ", New string [] {" Che "});
System. Out. println ("delete ---");
}
});
}
}
3. Enter DoS
> ADB Shell
# CD Data
# CD Data
CD Data
# Ls
Ls
Com. Android. Google
Com. Android. Fallback
Com. Android. Gallery
Com.android.html Viewer
Com. Android. providers. userdictionary
Com. Android. cardock
Com. Android. Development
Com. Android. defcontainer
Com. Android. server. VPN
Com. Android. soundrecorder
Com. Android. certinstaller
Com. Android. wallpaper. livepicker
Com. Android. netspeed
Com. Android. packageinstaller
Android. TTS
Com. Android. providers. Applications
Com. Android. speechrecorder
Com. Android. inputmethod. Latin
Com. Android. customlocale
Com. Android. inputmethod. Pinyin
Com. Android. providers. subscribedfeeds
Com. Android. providers. DRM
Com. Android. MMS
Com. Android. providers. Contacts
Com. Android. providers. Media
Com. svox. Pico
Com. Android. sdksetup
Com. Android. Term
Com. Android. providers. Settings
Com. Android. Phone
Com. Android. Launcher
Com. Android. providers. Telephony
Com. Android. providers. downloads
Com. Android. alarmclock
JP. co. omronsoft. openwnn
Com. Android. Contacts
Com. Android. Browser
Com. PC
Com. Android. Email
Com. Android. carhome
Com. Android. quicksearchbox
Com. Android. Music
Com. Android. spare_parts
Com. Android. Settings
Com. Android. Camera
Com. Android. protips
Com. Android. calculator2
Com. Android
# Cd com. Android
CD com. Android
# Ls
Ls
Lib
Databases
# Cd da
CD da
CD: Can't CD to DA
# CD database
CD database
CD: Can't CD to database
# Cd Databases
CD Databases
# Ls
Ls
Test_sqlite
# Sqlite3 test_sqlite
Sqlite3 test_sqlite
Sqlite3: not found
# Sqlite3 test_sqlite
Sqlite3 test_sqlite
Sqlite3: not found
# Sqlite3 test_sqlite
Sqlite3 test_sqlite
SQLite version 3.6.22
Enter ". Help" for instructions
Enter SQL statements terminated with ";"
SQLite>. schema // view the current plan
. Schema
Create Table android_metadata (locale text );
Create Table user (ID int, name varchar (15 ));
SQLite> select * from user;
Select * from user;
1 | Che
1 | Che
1 | Che
1 | Che
1 | Che
SQLite> select * from user;
Select * from user;
1 | Che
1 | Che
1 | Che
1 | Che
1 | Che
1 | Che
SQLite> select * from user;
Select * from user;
1 | Cheche
1 | Cheche
1 | Cheche
1 | Cheche
1 | Cheche
1 | Cheche
SQLite> select * from user;
Select * from user;
SQLite> select * from user;
Select * from user;
1 | Cheche
1 | Che
SQLite> select * from user;
Select * from user;
SQLite> select * from user;
Select * from user;
1 | Cheche
1 | Che
SQLite> select * from user;
Select * from user;
1 | Cheche
1 | Che
SQLite> select * from user;
Select * from user;
1 | Cheche
1 | Che
SQLite> select * from user;
Select * from user;
1 | Cheche
SQLite> select * from user;
Select * from user;
1 | Cheche
SQLite> select * from user;
Select * from user;
1 | Cheche
1 | Che
SQLite> select * from user;
Select * from user;
1 | Cheche
SQLite>