I am facing an issue with the database. Some times it works fine and other times it shows that the database is busy and locked. I believe the issue is with the close function when i try to use connection and call a method that use connection the code is the following read the only comment to know the issue please
Action deleteAction = new AbstractAction("Delete", deleteIcon) {
@Override
public void actionPerformed(ActionEvent e) {
String sql="delete from library where ID=?";
String message ="deleting data from database";
String title = "delete";
int reply = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) {
try{
pst=conn.prepareStatement(sql);
pst.setString(1,add8Value);
pst.execute();
add8Value = null;
Update_table();// this is the other method
}catch(Exception ex){
JOptionPane.showMessageDialog(null, "problem 3"+ex);
}finally{
try{
pst.close();
rs.close();
}catch(Exception ex){
JOptionPane.showMessageDialog(null, "problem is here 1" + ex);
}
}
}else{Update_table();}
here is the other function to read update of the table please check the issue
public void Update_table(){
String sql = "SELECT * FROM library";
try {
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}finally{
try{
rs.close();
pst.close();
}catch(Exception ex){
JOptionPane.showMessageDialog(null, ex);
}
}
}