0

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);
            }
        }

    }
keko
  • 3
  • 5
  • You haven't closed your database connection `conn` – Imesha Sudasingha Oct 11 '16 at 04:03
  • look at this http://stackoverflow.com/questions/8511901/system-data-sqlite-close-not-releasing-database-file – Maytham Fahmi Oct 11 '16 at 04:04
  • @ImeshaSudasingha if i closed the connection then i can only delete for one time then if i clicked the button again it show conn is closed if there a way to check if the connection is open using if statement that will be better coz connection in initialized in the contractor – keko Oct 11 '16 at 04:34
  • You get the error when *another* connection object still exists. – CL. Oct 11 '16 at 06:47
  • @keko You should create a new database connection inside `ConnectorDB()` and close the connection once done with the connection. – Imesha Sudasingha Oct 11 '16 at 07:50

0 Answers0