1919
2020package com .sample .encrypt .database ;
2121
22+ import android .annotation .SuppressLint ;
2223import android .content .ContentValues ;
2324import android .content .Context ;
2425import android .database .Cursor ;
2526
26- import net .sqlcipher .DatabaseUtils ;
27- import net .sqlcipher .database .SQLiteDatabase ;
28- import net .sqlcipher .database .SQLiteOpenHelper ;
27+ import net .zetetic . database .DatabaseUtils ;
28+ import net .zetetic .database . sqlcipher .SQLiteDatabase ;
29+ import net .zetetic .database . sqlcipher .SQLiteOpenHelper ;
2930
3031import java .util .ArrayList ;
3132
@@ -39,10 +40,12 @@ public class PersonDBHelper extends SQLiteOpenHelper {
3940 public static final String PERSON_COLUMN_ADDRESS = "address" ;
4041 private static final String DB_PASSWORD = "a_password" ;
4142
42- public PersonDBHelper (Context context ) {
43+ static {
44+ System .loadLibrary ("sqlcipher" );
45+ }
4346
44- super ( context , DATABASE_NAME , null , 1 );
45- SQLiteDatabase . loadLibs (context );
47+ public PersonDBHelper ( Context context ) {
48+ super (context , DATABASE_NAME , DB_PASSWORD , null , 1 , 0 , null , null , false );
4649 }
4750
4851 @ Override
@@ -60,7 +63,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
6063 }
6164
6265 public boolean insertPerson (String firstName , String lastName , String address ) {
63- SQLiteDatabase db = this .getWritableDatabase (DB_PASSWORD );
66+ SQLiteDatabase db = this .getWritableDatabase ();
6467 ContentValues contentValues = new ContentValues ();
6568 contentValues .put ("first_name" , firstName );
6669 contentValues .put ("last_name" , lastName );
@@ -71,19 +74,19 @@ public boolean insertPerson(String firstName, String lastName, String address) {
7174 }
7275
7376 public Cursor getData (int id ) {
74- SQLiteDatabase db = this .getReadableDatabase (DB_PASSWORD );
77+ SQLiteDatabase db = this .getReadableDatabase ();
7578 Cursor res = db .rawQuery ("select * from person where id=" + id + "" , null );
7679 return res ;
7780 }
7881
7982 public int numberOfRows () {
80- SQLiteDatabase db = this .getReadableDatabase (DB_PASSWORD );
83+ SQLiteDatabase db = this .getReadableDatabase ();
8184 int numRows = (int ) DatabaseUtils .queryNumEntries (db , PERSON_TABLE_NAME );
8285 return numRows ;
8386 }
8487
8588 public boolean updatePerson (Integer id , String firstName , String lastName , String address , float mileage ) {
86- SQLiteDatabase db = this .getWritableDatabase (DB_PASSWORD );
89+ SQLiteDatabase db = this .getWritableDatabase ();
8790 ContentValues contentValues = new ContentValues ();
8891 contentValues .put ("first_name" , firstName );
8992 contentValues .put ("last_name" , lastName );
@@ -94,16 +97,17 @@ public boolean updatePerson(Integer id, String firstName, String lastName, Strin
9497 }
9598
9699 public Integer deletePerson (Integer id ) {
97- SQLiteDatabase db = this .getWritableDatabase (DB_PASSWORD );
100+ SQLiteDatabase db = this .getWritableDatabase ();
98101 return db .delete ("person" ,
99102 "id = ? " ,
100103 new String []{Integer .toString (id )});
101104 }
102105
106+ @ SuppressLint ("Range" )
103107 public ArrayList <String > getAllPerson () {
104108 ArrayList <String > arrayList = new ArrayList <>();
105109
106- SQLiteDatabase db = this .getReadableDatabase (DB_PASSWORD );
110+ SQLiteDatabase db = this .getReadableDatabase ();
107111 Cursor res = db .rawQuery ("select * from person" , null );
108112 res .moveToFirst ();
109113
@@ -119,7 +123,7 @@ public ArrayList<String> getAllPerson() {
119123 }
120124
121125 public int count () {
122- SQLiteDatabase db = getReadableDatabase (DB_PASSWORD );
126+ SQLiteDatabase db = getReadableDatabase ();
123127 Cursor cursor = db .rawQuery ("select * from person" , null );
124128 try {
125129 if (cursor != null && cursor .getCount () > 0 ) {
0 commit comments