SQLite 操作 and DoS

前端之家收集整理的这篇文章主要介绍了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>
原文链接:https://www.f2er.com/sqlite/202689.html

猜你在找的Sqlite相关文章