I made a simple application for registering, deleting and searching for users using java + sqlite (netbeans and sqlite studio). I tested on 3 computers and everything worked correctly, however on a specific computer the behavior is:
I open the application once, I perform some insertion and / or deletion operations, I close the app and everything is ok.
I open the application again and I make more insertions and / or deletions and everything is ok.
I open again and from the moment I perform any operation, a .sqlite-journal file is created in the folder that when it is created all the operations I do are no longer saved. I close the application and it is still there. When I reopen the changes were not saved.
This happens only on this specific pc, in others the .sqlite-journal file is not created and everything works ok.
I've read this on sqlite website:
"SQLite normally stores all content in a single disk file. However, while performing a transaction, information necessary to roll back that transaction following a crash or power failure is stored in auxiliary journal files. These journal files have the same name as the original database file with the addition of -journal or -wal suffix.
SQLite must see the journal files in order to recover from a crash or power failure. If the journal files are moved, deleted, or renamed after a crash or power failure, then automatic recovery will not work and the database may go corrupt."
And I saw on the internet that in sqlite everything is already set to autocommit and sometimes it can go wrong and it saves in that journal. I already took the autocommit and manually put in the code to commit after each operation, but it did not solve.
The code for deletion is (the insertion is similar):
private void cmd_deletarintActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int p = JOptionPane.showConfirmDialog(null, "Você realmente quer deletar?", "Delete", JOptionPane.YES_NO_OPTION);
if (p==0) {
String sql = "delete from EleitoresInterior where id=?";
try {
conn.setAutoCommit(false);
pst = conn.prepareStatement(sql);
pst.setString(1, txt_idint.getText());
pst.execute();
conn.commit();
JOptionPane.showMessageDialog(null, "Dados apagados!");
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, e);
try {
if (conn != null) {
conn.rollback();
}
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "Problemas na conexão!");
}
}
finally{
try{
pst.close();
}
catch(Exception e){
}
}
Update_table2();
}
}
In that code, when I run the application, after the journal file is created it drops in the message "Problemas na conexão!", so at some point the connection is null, which is causing the error.