android.database.sqlite.SQLiteDatabaseLockedException:数据库被锁定(代码5):,编译时:PRAGMA journal_mode 在android.database.sqlite.SQLiteConnection.nativePrepareStatement(本机方法) 在android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:898) 在android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:643)
at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:325)
at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:299)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:220)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:198)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
这是我的代码
try {
db.beginTransaction();
String sql = "INSERT INTO " + DBHelperConstants.TABLE_DistrictMaster + " ( "
+DBHelperConstants.KEY_DistrictCode +" , " + DBHelperConstants.KEY_DistrictName + " , "
+DBHelperConstants.KEY_SubDistrictCode + " , " + DBHelperConstants.KEY_SubDistrictName + " , "
+DBHelperConstants.KEY_MarketUID +" , " + DBHelperConstants.KEY_MarketName + " , "
+DBHelperConstants.KEY_SubStkUID +" , " + DBHelperConstants.KEY_Population + " ) "
+ " VALUES (?,?,?,?,?,?,?,?);";
SQLiteStatement statement = db.compileStatement(sql);
for (int i = 0; i < list.size(); i++) {
DistrictMaster districtMaster = list.get(i);
statement.bindString(1, districtMaster.getDistrictCode());
statement.bindString(2, districtMaster.getDistrictName());
statement.bindString(3, districtMaster.getSubdistrictcode());
statement.bindString(4, districtMaster.getSubdistrictName());
statement.bindString(5, districtMaster.getMarketUid());
statement.bindString(6, districtMaster.getMarketName());
statement.bindString(7, districtMaster.getSubStkuid());
statement.bindString(8, districtMaster.getPopulation());
statement.execute();
}
db.setTransactionSuccessful();
Log.w("", "Done");
} catch (Exception e) {
Log.w("XML:", e);
} finally {
db.endTransaction();
}
}
答案 0 :(得分:0)
请验证,您可能忘记关闭与数据库的连接。如果数据库始终处于打开状态并且您没有关闭数据库,则无法编写任何内容。
答案 1 :(得分:0)
我正在添加空值,这就是为什么会出现此错误