try {
stmt = con.createStatement();
stmt.getConnection().setAutoCommit(false);
try {
for (String q : query) {
if (q != null && !q.equals("")) {
stmt.executeUpdate(q);
}
}
stmt.execute("COMMIT");
stmt.getConnection().setAutoCommit(true);
stmt.close();
JOptionPane.showMessageDialog(frame, "Details Successfully Added.",
"Information", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException ex) {
System.out.println("Rollback:\n " ex.getMessage());
stmt.execute("ROLLBACK");
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(frame,ex.getMessage(),
"Exception Occured", JOptionPane.ERROR_MESSAGE);
}
i have written above code to insert multiple records using transaction, but when i execute it, it sometimes gives me could not commit no transaction is running
and sometimes could not rollback no transaction is active
while the records are successfully getting inserted.
as i am new to sqlite and java, i am not getting what is the actual issue here, please anyone guide me or help me to make it run..
Aucun commentaire:
Enregistrer un commentaire