//this is my handler class
public class DBHandler extends SQLiteOpenHelper{
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "feedbackDB.db";
private static final String TABLE_FEEDBACK = "feedback";
public DBHandler(Context context) {
super(context,context.getExternalFilesDir(null).getAbsolutePath()+DATABASE_NAME, null, DATABASE_VERSION);
}
public void openDataBase(SQLiteDatabase db) throws SQLException {
//Open the database
String myPath = context.getExternalFilesDir(null).getAbsolutePath() + DATABASE_NAME;
db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}
问问题
259 次
1 回答
1
在构造函数中声明 DB_PATH 值并在需要时使用它,这样您就不需要每次都分配
public DBHandler(Context context)
{
super(context, DB_NAME, null, 1);
this.myContext = context;
DB_PATH = Environment.getExternalStorageDirectory()
+ File.separator + "/.folder name/" + File.separator;
File f = new File(DB_PATH);
f.mkdirs();
}
并将其用作DB_PATH+DATABASE_NAME
执行数据库操作
于 2013-09-18T07:37:01.530 回答