I use SQLite for a Gluon Mobile App in my Android. When I access the database for the first time it works without problem, but the another time I have a Exception:
"Android.database.sqllite.SQLiteDatabaseLocked Exception:database is locked (code 5)
The code to access the database is:
if (Platform.isAndroid()) {
Class.forName("org.sqldroid.SQLDroidDriver");
try {
dir = Services.get(StorageService.class)
.map(s -> s.getPrivateStorage().get())
.orElseThrow(() -> new IOException("Error: PrivateStorage not available"));
File db = new File(dir, DB_NAME);
DBUtils.copyDatabase("/databases/", dir.getAbsolutePath(),
DB_NAME);
dbUrl = dbUrl + db.getAbsolutePath();
System.out.println(dbUrl);
c = DriverManager.getConnection(dbUrl);
} catch (IOException ex) {
Alert alert = new Alert(AlertType.CONFIRMATION, ex.getClass().getName());
alert.setContentText(ex.getMessage());
alert.showAndWait();
}
c.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM COMPANYn;");
while (rs.next()) {
ObservableList<String> items = FXCollections.observableArrayList();
String name1 = rs.getString("name");
// System.out.println(name1);
items.addAll(name1);
ET.getItems().addAll(items);
ET.getSelectionModel().select(0);
}
rs.close();
stmt.close();
c.close();
Somebody can help me please. Thank for help.