1. [代碼][Java]代碼 ? ??
public class Database {
?
private static DbOpenHelper mDbHelper;
private static final int DB_VERSION = 1;
private static final String DB_NAME = "pdf.db";
?
public static void close() {
if(mDbHelper != null) {
mDbHelper.close();
mDbHelper = null;
}
}
?
public static SQLiteDatabase getDb(Context context) {
DbOpenHelper helper = getDbOpenHelper(context);
return helper.getWritableDatabase();
}
?
public static void writeMessageToDb(SQLiteDatabase db, String name,?
String path) {
ContentValues values = new ContentValues();
values.put(PDF.name.name(), name);
values.put(PDF.path.name(), path);
db.insert(PDF.TABLE_NAME, null, values);
}
?
public static HashMap<String, String> loadMessageFromDb(SQLiteDatabase db) {
Cursor cursor = db.query(PDF.TABLE_NAME, null, null, null, null, null, null);
HashMap<String, String> result = new HashMap<String, String>();
while(cursor.moveToNext()) {http://www.huiyi8.com/moban/
String name = cursor.getString(cursor.getColumnIndex(PDF.name.name()));
String path = cursor.getString(cursor.getColumnIndex(PDF.path.name()));
?
?
result.put(name, path);
}
cursor.close();
return result;
}
?
private static DbOpenHelper getDbOpenHelper(Context context) {
if(mDbHelper == null)
mDbHelper = new DbOpenHelper(context, DB_NAME, DB_VERSION);
?
return mDbHelper;
}
?
private static class DbOpenHelper extends SQLiteOpenHelper {
?
public DbOpenHelper(Context context, String name, int version) {
super(context, name, null, version);
}
?
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + PDF.TABLE_NAME + " (" +
PDF._id.name() + " INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
PDF.name.name() + " TEXT NOT NULL, " +?
PDF.path.name() + " TEXT NOT NULL" +
");"
);
}
?
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
dropTables(db);
html模板
onCreate(db);
}
?
private void dropTables(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + PDF.TABLE_NAME);
}
}
?
enum PDF {
_id,
name,
path;
?
static final String TABLE_NAME = "PDF";
}
}
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
