我想打开一个自定义路径,创建一个数据库,创建一个表并插入值。
public class MySQLiteOpenHelper extends SQLiteOpenHelper {
MySQLiteOpenHelper(Context context) {
super(context, "/mnt/sdcard/database_name.db", null, 0);
}
}
public class DBHandler extends SQLiteOpenHelper {
public Context context;
public static final String DATABASE_PATH=Environment.getExternalStorageDirectory().getAbsolutePath()+"/WebService/Databases/";
private static final String DATABASE_NAME="database_name.db";
public DBHandler(Context context){
//Create the Database
super(context, DATABASE_PATH+DATABASE_NAME, null, 1);
this.context=context;
Log.i("databaseService","Database Created ");
}
}
Stacktrace:
E/SQLiteLog: (14) cannot open file at line 35807 of [553a923c82]
(14) os_unix.c:35807: (2) open(/storage/emulated/0/WebService/Databases/database_name.db) -
E/SQLiteDatabase: Failed to open database '/storage/emulated/0/WebService/Databases/database_name.db'.
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:211)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:195)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:493)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:200)