hi all,
I have a small problem with my code, I am trying to create (if that
does not exist) and open connection to sqlite but it fails to open. Im
doing that cos I know that my db can be big and may not fit into
mobile local storage.
1. I get path to external storage and get the full path to sqlite file
(both rootFolder (ie, "sqlitedb") and name (ie. "mydb.db") may not
exists on sd card)
private String getExternal(String rootFolder, String name) {
final String externalStorageState =
Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(externalStorageState)) {
externalReadOnly = false;
} else if
(Environment.MEDIA_MOUNTED_READ_ONLY.equals(externalStorageState)) {
externalReadOnly = true;
} else {
throw new SQLiteDiskIOException("couldn't obtain external
data store");
}
return new
StringBuilder(Environment.getExternalStorageDirectory().
getPath()).append(File.pathSeparator).
append(rootFolder).
append(File.pathSeparator).
append(name).
toString();
}
2. im trying to open the sqlite db with given path
final String path = getExternal(root, name);
Log.d(TAG, "opening readonly database at " + path);
db = SQLiteDatabase.openDatabase(path, null,
SQLiteDatabase.OPEN_READWRITE & SQLiteDatabase.CREATE_IF_NECESSARY);
but this is throwing exception
D/SqliteExternalHelper( 362): opening writable database at /
sdcard:db:my_external_db.db
E/Database( 362): sqlite3_open_v2("/sdcard:db:my_external_db.db",
&handle, 2, NULL) failed
D/AndroidRuntime( 362): Shutting down VM
W/dalvikvm( 362): threadid=3: thread exiting with uncaught exception
(group=0x4001b188)
E/AndroidRuntime( 362): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime( 362): android.database.sqlite.SQLiteException:
unable to open database file
E/AndroidRuntime( 362): at
android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
E/AndroidRuntime( 362): at
android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:
1697)
E/AndroidRuntime( 362): at
android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:
738)
E/AndroidRuntime( 362): at
info.kamiseq.db.SqliteExternalHelper.getWritable(SqliteExternalHelper.java:
126)
E/AndroidRuntime( 362): at
info.kamiseq.db.SqliteExternalHelper.getWritable(SqliteExternalHelper.java:
97)
I am a bit confused about how this should work,
thank for help.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en