-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/weihuagu/receiptnotice/DatabaseHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.weihuagu.receiptnotice; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
public class DatabaseHelper extends SQLiteOpenHelper { | ||
//数据库版本号 | ||
private static Integer Version = 1; | ||
|
||
public DatabaseHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) { | ||
super(context, name, factory, version); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
String sql = "create table plat(id integer primary key autoincrement,name varchar(64),address varchar(64))"; | ||
db.execSQL(sql); | ||
|
||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
|
||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/weihuagu/receiptnotice/util/DataBaseHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.weihuagu.receiptnotice.util; | ||
|
||
import android.database.sqlite.SQLiteDatabase; | ||
|
||
import com.weihuagu.receiptnotice.DatabaseHelper; | ||
import com.weihuagu.receiptnotice.MainApplication; | ||
|
||
public class DataBaseHolder { | ||
//创建 SingleObject 的一个对象 | ||
private static DataBaseHolder instance = new DataBaseHolder(); | ||
public DatabaseHelper dbHelper; | ||
public SQLiteDatabase sqliteDatabase; | ||
|
||
//让构造函数为 private,这样该类就不会被实例化 | ||
private DataBaseHolder(){ | ||
createDataBase(); | ||
} | ||
|
||
//获取唯一可用的对象 | ||
public static DataBaseHolder getInstance(){ | ||
return instance; | ||
} | ||
|
||
private void createDataBase(){ | ||
dbHelper = new DatabaseHelper(MainApplication.getAppContext(),"receiptnotice",null,1); | ||
sqliteDatabase = dbHelper.getWritableDatabase(); | ||
} | ||
|
||
public SQLiteDatabase getDateBase(){ | ||
return sqliteDatabase; | ||
} | ||
} |