SQLiteDatabase用路径打开特定数据库

时间:2013-07-15 10:20:13

标签: android

我想打开一个包含所有短信和短信息的数据库。我想这样做因为我需要进行原始查询,所以我需要让它工作。 我试图这样做:

    try{
      SQLiteDatabase sqLiteDatabase = SQLiteDatabase.openDatabase("/data/data/com.android.providers/telephony/databases/mmssms.db", null, SQLiteDatabase.OPEN_READWRITE);
    }catch(Exception e){
       e.printStackTrace();
    }

我收到这样的错误:

07-15 10:13:11.784: E/SQLiteLog(13014): (14) cannot open file at line 30176 of [00bb9c9ce4]
07-15 10:13:11.784: E/SQLiteLog(13014): (14) os_unix.c:30176: (2) open(/data/data/com.android.providers/telephony/databases/mmssms.db) - 
07-15 10:13:12.084: E/SQLiteDatabase(13014): Failed to open database '/data/data/com.android.providers/telephony/databases/mmssms.db'.
07-15 10:13:12.084: E/SQLiteDatabase(13014): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at ppm.messenger.androidppmmessenger.MainActivity.onCreate(MainActivity.java:62)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.app.Activity.performCreate(Activity.java:5104)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.os.Looper.loop(Looper.java:137)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at android.app.ActivityThread.main(ActivityThread.java:5041)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at java.lang.reflect.Method.invokeNative(Native Method)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at java.lang.reflect.Method.invoke(Method.java:511)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-15 10:13:12.084: E/SQLiteDatabase(13014):    at dalvik.system.NativeStart.main(Native Method)
07-15 10:13:12.094: W/System.err(13014): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
07-15 10:13:12.094: W/System.err(13014):    at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
07-15 10:13:12.104: W/System.err(13014):    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
07-15 10:13:12.116: W/System.err(13014):    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
07-15 10:13:12.124: W/System.err(13014):    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
07-15 10:13:12.134: W/System.err(13014):    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
07-15 10:13:12.134: W/System.err(13014):    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
07-15 10:13:12.147: W/System.err(13014):    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
07-15 10:13:12.147: W/System.err(13014):    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
07-15 10:13:12.154: W/System.err(13014):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
07-15 10:13:12.166: W/System.err(13014):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
07-15 10:13:12.174: W/System.err(13014):    at ppm.messenger.androidppmmessenger.MainActivity.onCreate(MainActivity.java:62)
07-15 10:13:12.174: W/System.err(13014):    at android.app.Activity.performCreate(Activity.java:5104)
07-15 10:13:12.185: W/System.err(13014):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-15 10:13:12.194: W/System.err(13014):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-15 10:13:12.194: W/System.err(13014):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-15 10:13:12.204: W/System.err(13014):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-15 10:13:12.214: W/System.err(13014):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-15 10:13:12.224: W/System.err(13014):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 10:13:12.234: W/System.err(13014):    at android.os.Looper.loop(Looper.java:137)
07-15 10:13:12.234: W/System.err(13014):    at android.app.ActivityThread.main(ActivityThread.java:5041)
07-15 10:13:12.244: W/System.err(13014):    at java.lang.reflect.Method.invokeNative(Native Method)
07-15 10:13:12.244: W/System.err(13014):    at java.lang.reflect.Method.invoke(Method.java:511)
07-15 10:13:12.254: W/System.err(13014):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-15 10:13:12.284: W/System.err(13014):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-15 10:13:12.294: W/System.err(13014):    at dalvik.system.NativeStart.main(Native Method)

我想知道如何正确打开这个数据库。

1 个答案:

答案 0 :(得分:1)

你的问题并不新鲜。看起来您需要了解与数据库服务器的连接是如何工作的一些信息。

已经给出了答案HERE