Android SQLite資料庫

來源:互聯網
上載者:User

參考《Android 開發權威指南》

1 sqlite 工具sqlite database browsersqlite expert professionalsqlite developersqlitespy 2 SQLiteOpenHelperonCreate(SQLiteDatabase db) // 檢查資料庫檔案 name.db 是否存在,不存在則調用這個方法,一般是建立資料表onUpgrade(SQLiteDatabase db, int olderVersion, int newVersion) // 比較版本號碼,不同則調用這個方法,一般是刪除老的資料庫,建立新的資料庫 3 SimpleCursorAdapter資料庫和視圖控制項綁定SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to); 4 不使用OpenHelper進行資料庫操作,這樣的方法可以在sdcard中建立資料庫檔案,一個缺陷是沒有安全執行緒保障和資料庫版本管理SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase("/sdcrad/name.db", null);db.execSQL("sql");Cursor c = db.rawQuery("sql", new String[] {});c.moveToFirst(); // 必須執行moveToFirst 或moveToNext 或 moveToPosition,因為指標在第0條記錄之前 5 資料庫隨apk發布namedb.db放在raw目錄下 InputStream is = getResources().openRawResource(R.raw.namedb);FileOutputStream fos = new FileOutputStream("/sdcard/namedb.db");byte[] buffer = new byte[8192];int count = 0;while((count = is.read(buffer) >= 0){fos.write(buffer,0,count);}fos.close();is.close();// 後面的操作和第4條就是一樣的了,需要許可權 WRITE_EXTERNAL_STORAGE 6 記憶體資料庫和第4條基本一樣不同之處在於SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(null, null);
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.