create table if not exists biao(_id Integer primary key autoincrement,data text)
创建表的时进行判断是否已存在表
C:\Users\Administrator>adb shell 初始
# ls
ls
config
cache
sdcard
acct
mnt
vendor
d
etc
ueventd.rc
ueventd.goldfish.rc
system
sys
sbin
proc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev
# cd data/data 打开data 文件夹
cd data/data
# ls
ls
com.example.test_sqllite
com.android.phone
com.android.development
com.android.email
com.android.calculator2
com.android.sdksetup
com.android.camera
com.android.protips
com.android.providers.media
com.android.contacts
com.android.systemui
com.android.netspeed
com.android.certinstaller
com.android.packageinstaller
com.android.browser
com.android.providers.userdictionary
com.android.deskclock
com.android.term
com.android.settings
com.android.speechrecorder
com.android.spare_parts
com.android.mms
com.android.providers.contacts
com.android.customlocale
com.android.providers.drm
com.android.providers.telephony
com.android.launcher
com.android.providers.subscribedfeeds
com.android.gallery
com.android.providers.downloads.ui
com.android.inputmethod.pinyin
com.android.soundrecorder
android.tts
com.android.inputmethod.latin
com.svox.pico
com.android.fallback
com.android.wallpaper.livepicker
com.android.providers.applications
com.android.music
jp.co.omronsoft.openwnn
com.android.providers.settings
com.android.server.vpn
com.android.defcontainer
com.android.quicksearchbox
com.android.htmlviewer
com.android.providers.downloads
#
#
#
# cd com.example.test_sqllite 打开对应的项目
cd com.example.test_sqllite
# ls
ls
lib
databases
.exit
#
#
# ls
ls
data3.db
data2.db
data1.db
data.db
# sqlite3 data3.db 打开数据库
sqlite3 data3.db
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> show tables;
show tables;
Error: near "show": syntax error
sqlite> .table
.table
android_metadata biao
sqlite> select * from biao
select * from biao
...> ;
;
1|閫氳繃sql鎻掑叆鏁版嵁
sqlite> insert into biao(data) values('123');
insert into biao(data) values('123');
sqlite> select * from biao
select * from biao
...> ;
;
1|閫氳繃sql鎻掑叆鏁版嵁
2|123
sqlite> create table if not exists biao(_id Integer primary key autoincrement,da
ta text);
create table if not exists biao(_id Integer primary key autoincrement,data text)
;
sqlite> select data from biao where _id=1;
select data from biao where _id=1;
閫氳繃sql鎻掑叆鏁版嵁
得到插入数据之后的自增id;
sqlite> insert into biao (data) values('x');
insert into biao (data) values('x');
sqlite> select * from biao;
select * from biao;
2|123
3|1234
5|x
sqlite> select last_insert_rowid();
select last_insert_rowid();
5
sqlite>
android 代码:
String s=ed.getText().toString();
insert="insert into biao(data) values('" +s+
"')";
Log.i("TGA", ""+insert);
liteDatabase.execSQL(insert);
Cursor cur=liteDatabase.rawQuery("select LAST_INSERT_ROWID() ",null);
cur.moveToFirst();
// int numColumn=cur.getColumnIndex("_id");
result=cur.getInt(0);
创建表的时进行判断是否已存在表
C:\Users\Administrator>adb shell 初始
# ls
ls
config
cache
sdcard
acct
mnt
vendor
d
etc
ueventd.rc
ueventd.goldfish.rc
system
sys
sbin
proc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev
# cd data/data 打开data 文件夹
cd data/data
# ls
ls
com.example.test_sqllite
com.android.phone
com.android.development
com.android.email
com.android.calculator2
com.android.sdksetup
com.android.camera
com.android.protips
com.android.providers.media
com.android.contacts
com.android.systemui
com.android.netspeed
com.android.certinstaller
com.android.packageinstaller
com.android.browser
com.android.providers.userdictionary
com.android.deskclock
com.android.term
com.android.settings
com.android.speechrecorder
com.android.spare_parts
com.android.mms
com.android.providers.contacts
com.android.customlocale
com.android.providers.drm
com.android.providers.telephony
com.android.launcher
com.android.providers.subscribedfeeds
com.android.gallery
com.android.providers.downloads.ui
com.android.inputmethod.pinyin
com.android.soundrecorder
android.tts
com.android.inputmethod.latin
com.svox.pico
com.android.fallback
com.android.wallpaper.livepicker
com.android.providers.applications
com.android.music
jp.co.omronsoft.openwnn
com.android.providers.settings
com.android.server.vpn
com.android.defcontainer
com.android.quicksearchbox
com.android.htmlviewer
com.android.providers.downloads
#
#
#
# cd com.example.test_sqllite 打开对应的项目
cd com.example.test_sqllite
# ls
ls
lib
databases
.exit
#
#
# ls
ls
data3.db
data2.db
data1.db
data.db
# sqlite3 data3.db 打开数据库
sqlite3 data3.db
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> show tables;
show tables;
Error: near "show": syntax error
sqlite> .table
.table
android_metadata biao
sqlite> select * from biao
select * from biao
...> ;
;
1|閫氳繃sql鎻掑叆鏁版嵁
sqlite> insert into biao(data) values('123');
insert into biao(data) values('123');
sqlite> select * from biao
select * from biao
...> ;
;
1|閫氳繃sql鎻掑叆鏁版嵁
2|123
sqlite> create table if not exists biao(_id Integer primary key autoincrement,da
ta text);
create table if not exists biao(_id Integer primary key autoincrement,data text)
;
sqlite> select data from biao where _id=1;
select data from biao where _id=1;
閫氳繃sql鎻掑叆鏁版嵁
得到插入数据之后的自增id;
sqlite> insert into biao (data) values('x');
insert into biao (data) values('x');
sqlite> select * from biao;
select * from biao;
2|123
3|1234
5|x
sqlite> select last_insert_rowid();
select last_insert_rowid();
5
sqlite>
android 代码:
String s=ed.getText().toString();
insert="insert into biao(data) values('" +s+
"')";
Log.i("TGA", ""+insert);
liteDatabase.execSQL(insert);
Cursor cur=liteDatabase.rawQuery("select LAST_INSERT_ROWID() ",null);
cur.moveToFirst();
// int numColumn=cur.getColumnIndex("_id");
result=cur.getInt(0);