日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android数据库--Sqlcipher的使用(一)

發(fā)布時(shí)間:2025/3/21 Android 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android数据库--Sqlcipher的使用(一) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、下載官方支持包:https://s3.amazonaws.com/sqlcipher/3.2.0/sqlcipher-for-android-community-v3.2.0.zip

? ? ?Github地址:https://github.com/sqlcipher/android-database-sqlcipher

2、本博客使用Android Studio開發(fā),Eclipse怎樣使用Sqlcipher大家可以到網(wǎng)上搜索。

3、需要導(dǎo)入以下包及文件。如何導(dǎo)入Jar包可以參考我的博客http://www.cnblogs.com/begin1949/p/4966542.html。

4、我們重寫一下SqliteOpenHelper類。這里注意一下引用的類來自于net.sqlcipher.database而不是谷歌官方的sqlite包。

import android.content.Context;import net.sqlcipher.database.SQLiteDatabase; import net.sqlcipher.database.SQLiteOpenHelper;public class MyDatabaseHelper extends SQLiteOpenHelper {public static final String CREATE_TABLE = "create table Book(name text,pages integer)";public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactoryfactory, int version) {super(context, name, factory, version);}@Overridepublic void onCreate(SQLiteDatabase sqLiteDatabase) {sqLiteDatabase.execSQL(CREATE_TABLE);}@Overridepublic void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {} }

5、接下來即可使用了。

import android.content.ContentValues; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.View; import android.widget.Button; import android.widget.TextView;import com.sqlcipher.R;import net.sqlcipher.Cursor; import net.sqlcipher.database.SQLiteDatabase;public class Use1Activity extends FragmentActivity implements View.OnClickListener {private SQLiteDatabase db;private MyDatabaseHelper dbHelper;private Button mBtnAdd;private Button mBtnQuery;private TextView mTvShow;private String result;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_use1);initView();}private void initView() {SQLiteDatabase.loadLibs(this);dbHelper = new MyDatabaseHelper(this, "demo.db", null, 1);db = dbHelper.getWritableDatabase("secret_key");mBtnAdd = (Button) findViewById(R.id.add_data);mBtnQuery = (Button) findViewById(R.id.query_data);mTvShow = (TextView) findViewById(R.id.tv_show);mBtnAdd.setOnClickListener(this);mBtnQuery.setOnClickListener(this);}@Overridepublic void onClick(View v) {if (v == mBtnAdd) {ContentValues values = new ContentValues();values.put("name", "密碼");values.put("pages", 566);db.insert("Book", null, values);} else if (v == mBtnQuery) {Cursor cursor = db.query("Book", null, null, null, null, null, null);if (cursor != null) {while (cursor.moveToNext()) {String name = cursor.getString(cursor.getColumnIndex("name"));int pages = cursor.getInt(cursor.getColumnIndex("pages"));result += "book?name?is?" + name + "\n";result += "book?pages?is?" + pages + "\n";}}cursor.close();mTvShow.setText(result);result = "";}} }

6、參考博文:https://discuss.zetetic.net/t/android-studio-integration/65

? ? ? ? ? ? ? ? ? ?http://blog.csdn.net/sziicool/article/details/18728153

轉(zhuǎn)載于:https://www.cnblogs.com/begin1949/p/4985883.html

總結(jié)

以上是生活随笔為你收集整理的Android数据库--Sqlcipher的使用(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。