久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

Android中如何對(duì)數(shù)據(jù)庫(kù)進(jìn)行操作

本篇內(nèi)容介紹了“Android中如何對(duì)數(shù)據(jù)庫(kù)進(jìn)行操作”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

堅(jiān)守“ 做人真誠(chéng) · 做事靠譜 · 口碑至上 · 高效敬業(yè) ”的價(jià)值觀,專業(yè)網(wǎng)站建設(shè)服務(wù)10余年為成都水處理設(shè)備小微創(chuàng)業(yè)公司專業(yè)提供成都企業(yè)網(wǎng)站定制營(yíng)銷網(wǎng)站建設(shè)商城網(wǎng)站建設(shè)手機(jī)網(wǎng)站建設(shè)小程序網(wǎng)站建設(shè)網(wǎng)站改版,從內(nèi)容策劃、視覺(jué)設(shè)計(jì)、底層架構(gòu)、網(wǎng)頁(yè)布局、功能開發(fā)迭代于一體的高端網(wǎng)站建設(shè)服務(wù)。

一個(gè)好的習(xí)慣是創(chuàng)建一個(gè)輔助類來(lái)簡(jiǎn)化你的Android數(shù)據(jù)庫(kù)交互??紤]創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)適配器,來(lái)添加一個(gè)與數(shù)據(jù)庫(kù)交互的包裝層。它應(yīng)該提供直觀的、強(qiáng)類型的方法,如添加、刪除和更新項(xiàng)目。數(shù)據(jù)庫(kù)適配器還應(yīng)該處理查詢和對(duì)創(chuàng)建、打開和關(guān)閉數(shù)據(jù)庫(kù)的包裝。

它還常用靜態(tài)的Android數(shù)據(jù)庫(kù)常量來(lái)定義表的名字、列的名字和列的索引。下面的代碼片段顯示了一個(gè)標(biāo)準(zhǔn)數(shù)據(jù)庫(kù)適配器類的框架。它包括一個(gè)SQLiteOpenHelper類的擴(kuò)展類,用于簡(jiǎn)化打開、創(chuàng)建和更新數(shù)據(jù)庫(kù)。

import android.content.Context;   import android.database.*;   import android.database.sqlite.*;   import android.database.sqlite.SQLiteDatabase.CursorFactory;   import android.util.Log;   public class MyDBAdapter    {  // The name and column index of each column in your database.   public static final String KEY_NAME=”name”;   public static final int NAME_COLUMN = 1;       // TODO: Create public field for each column in your table.   // SQL Statement to create a new database.   private static final String DATABASE_CREATE = “create table “ +   DATABASE_TABLE + “ (“ + KEY_ID + “ integer primary key autoincrement, “ +   KEY_NAME + “ text not null);”;       // Variable to hold the database instance   private SQLiteDatabase db;       // Context of the application using the database.   private final Context context;       // Database open/upgrade helper   private myDbHelper dbHelper;       public MyDBAdapter(Context _context) {   context = _context;   dbHelper = new myDbHelper(context, DATABASE_NAME, null, DATABASE_VERSION);   }       public MyDBAdapter open() throws SQLException {   db = dbHelper.getWritableDatabase();   return this;   }       public void close() {   db.close();   }       public long insertEntry(MyObject _myObject) {   ContentValues contentValues = new ContentValues();   // TODO fill in ContentValues to represent the new row   return db.insert(DATABASE_TABLE, null, contentValues);   }       public boolean removeEntry(long _rowIndex) {   return db.delete(DATABASE_TABLE, KEY_ID + “=” + _rowIndex, null) > 0;   }   public Cursor getAllEntries () {   return db.query(DATABASE_TABLE, new String[] {KEY_ID, KEY_NAME},   null, null, null, null, null);   }   public MyObject getEntry(long _rowIndex) {   MyObject objectInstance = new MyObject();   // TODO Return a cursor to a row from the database and   // use the values to populate an instance of MyObject   return objectInstance;   }   public int updateEntry(long _rowIndex, MyObject _myObject) {   String where = KEY_ID + “=” + _rowIndex;   ContentValues contentValues = new ContentValues();   // TODO fill in the ContentValue based on the new object   return db.update(DATABASE_TABLE, contentValues, where, null);   }       private static class myDbHelper extends SQLiteOpenHelper    {   public myDbHelper(Context context, String name, CursorFactory factory, int version) {   super(context, name, factory, version);   }       // Called when no database exists in   // disk and the helper class needs   // to create a new one.   @Override   public void onCreate(SQLiteDatabase _db) {   _db.execSQL(DATABASE_CREATE);   }

“Android中如何對(duì)數(shù)據(jù)庫(kù)進(jìn)行操作”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

網(wǎng)站名稱:Android中如何對(duì)數(shù)據(jù)庫(kù)進(jìn)行操作
網(wǎng)站URL:http://sd-ha.com/article6/gpipog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、定制網(wǎng)站、外貿(mào)建站、企業(yè)建站、域名注冊(cè)、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作