欢迎来到天天文库
浏览记录
ID:6029606
大小:38.50 KB
页数:7页
时间:2017-12-31
《android中sqlitedatabase的使用》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、packagecom.Aina.Android; importandroid.app.Activity; importandroid.app.AlertDialog; importandroid.content.ContentValues; importandroid.content.DialogInterface; importandroid.database.Cursor; importandroid.database.sqlite.SQLiteDatabase; importandroid.os.Bundle; importandroid.widget.ListAd
2、apter; importandroid.widget.ListView; importandroid.widget.SimpleCursorAdapter; publicclassTestextendsActivity{ /**Calledwhentheactivityisfirstcreated.*/ privateListViewlv=null; privateSQLiteDatabasemSQLiteDatabase=null; privatestaticfinalStringDATABASE_NAME="Test.db"; priva
3、testaticfinalStringTABLE_NAME="table_test"; privatestaticfinalStringCOLUMN_ID="_id";//INTEGERPRIMARYKEY privatestaticfinalStringCOLUMN_NAME="name";//TEXT privatestaticfinalStringCOLUMN_AGE="age";//INTEGER privatestaticfinalStringCREATE_TABLE="CREATETABLEIFNOTEXISTS" +TAB
4、LE_NAME+"("+COLUMN_ID+"INTEGERPRIMARYKEY," +COLUMN_NAME+"TEXT,"+COLUMN_AGE+"INTEGER)"; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); lv=(ListView)this.findViewById(R.id.ListView0
5、1); try{ mSQLiteDatabase=this.openOrCreateDatabase(DATABASE_NAME, Activity.MODE_PRIVATE,null); }catch(Exceptionex){ this.ShowDialog("打开或者创建数据库异常:"+ex.getMessage()); } try{ mSQLiteDatabase.execSQL(CREATE_TABLE);
6、 }catch(Exceptionex){ this.ShowDialog("创建表异常:"+ex.getMessage()); } //this.InsertData(); //this.InsertData2(); //this.AddData(); //this.UpdateData(); //this.UpdateData2(); //this.UpdateData3(); //this.DeleteData();
7、 //this.DeleteData2(); //this.DeleteData3(); this.SelectData(); } @Override protectedvoidonPause(){ super.onPause(); mSQLiteDatabase.close();//关闭数据库 }
此文档下载收益归作者所有