在我的应用程序中,我尝试通过以下代码打开现有的android数据库来修改其内容:
String DB_PATH = "/data/data/com.sec.android.provider.logsprovider/databases/";
String DB_NAME = "logs.db";
..........................
SQLiteDatabase mSqLiteDatabase = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, SQLiteDatabase.OPEN_READWRITE);
数据库的路径是正确的,我也更改了数据库文件的权限。但是在编译时总会出现“无法打开数据库文件(代码14):”的错误:PRAGMA journal_mode“
我的manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.logsfiller"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.logsfiller.LogFillerActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我做错了吗?请帮忙! 谢谢!
答案 0 :(得分:1)
不要提及db
的扩展名试试这个,它会起作用。
String DB_NAME = "logs";
编辑:
将此课程添加到您的课程
public class DBAdapter {
final Context context;
DatabaseHelper DBHelper;
SQLiteDatabase db;
public DBAdapter(Context ctx) {
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, "logs", null, 1);
}
}
public DBAdapter open(String path, String dbName) throws SQLException {
db = DBHelper.getWritableDatabase();
String destPath = path + "/" + dbName;
db = db.openDatabase(destPath, null, 0);
return this;
}
}
并调用open()
方法,例如,
DBAdapter db = new DBAdapter(this);
String DB_PATH = "/data/data/com.sec.android.provider.logsprovider/databases/";
String DB_NAME = "logs";
db.open(DB_PATH, DB_NAME);
它对我有用,当然它对你有用