SQLite 操作 and DoS

Androidsqlite数据操作

(2010-12-06 10:27:49)
标签

it

1.sqliteHelper.java:创建数据库,表单 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 context,String name,CursorFactory factory,int version) { super(context,name,factory,version); } @Override public void onCreate(sqliteDatabase db) { System.out.println("Create DB"); db.execsql("create table user(id int,name varchar(15))"); //创建表单 } @Override public void onUpgrade(sqliteDatabase db,int oldVersion,int newVersion) { // Todo Auto-generated method stub } } 2.sqliteActivity.java:实现数据操作,增删改查 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(){ //创建数据库 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); //空间ID变量声明 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() { //创建数据库 @Override public void onClick(View v) { // Todo Auto-generated method stub db(); System.out.println("创建数据库"); } }); this.buttSelect.setonClickListener(new View.OnClickListener() { //查询 @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() { //添加 @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",value); System.out.println("insert ---"); } }); this.buttUpdate.setonClickListener(new View.OnClickListener() { //更新 @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,new String[]{"1"}); System.out.println("update ---"); } }); this.buttDelete.setonClickListener(new View.OnClickListener() { //删除 @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.进入DOS >>adb shell # cd data # cd data cd data # ls ls com.android.google com.android.fallback com.android.gallery com.android.htmlviewer 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 a ";" sqlite> .schema //查看当前计划 .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>

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能