DBHelper.java
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.sunvote.xpadapp.db;
import android.database.sqlite.SQLiteDatabase;
import com.sunvote.util.LogUtil;
import java.io.File;
/**
* 人大通用版XPadAppRD重构
*/
public class DBHelper {
// 得到SD卡路径
private final String DATABASE_PATH = android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "sunvote" + File.separator;
private final String DATABASE_FILENAME = "Meeting.db";
private int mId;
public DBHelper(int meetingId) {
mId = meetingId;
}
// 得到操作数据库的对象
public SQLiteDatabase openDatabase(int confId) {
try {
boolean b = false;
mId = confId;
if(confId == 0){
LogUtil.e("DBHelper", "openDatabase with Error confid 0");
return null;
}
// 得到数据库的完整路径名
String databaseFilename = DATABASE_PATH + mId + "/" + DATABASE_FILENAME;
if (!(new File(databaseFilename)).exists()) {
LogUtil.e("DBHelper", "db not exists");
}
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFilename, null);
return database;
} catch (Exception e) {
LogUtil.e("DBHelper",e);
}
return null;
}
}