Skip to content

Commit

Permalink
加入数据库,以便加入分析
Browse files Browse the repository at this point in the history
  • Loading branch information
WeihuaGu committed Jul 23, 2020
1 parent 8837034 commit ceced2d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions app/src/main/java/com/weihuagu/receiptnotice/DatabaseHelper.java
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) {

}
}
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;
}
}

0 comments on commit ceced2d

Please sign in to comment.