SQLITE Database is locked in java (IDE NetBeans)

13,986

You must close any open connection before open a new one. You're opening a new connection conn = Sahil_Computers.ConnecrDb(); every time a button is pressed but you never close it. Add conn.close(); to your finally blocks.

Some off-topic concern: use PreparedStatement#executeUpdate() instead PreparedStatement#execute() when you need to execute an INSERT/UPDATE/DELETE statement.

Share:
13,986
Rafi Abro
Author by

Rafi Abro

The first thing you must know about me is that I always stand what I stand for. Good? The second thing you must know about yourself listening to me is that words are tricky. So when you know what me a stand for, when me explain a thing to you, you must never try to look 'pon it in a different way from what me a stand for. I am Me. In all the world, there is no one else exactly like me. Everything that comes out of me is authentically mine, because I alone chose it -- I own everything about me: my body, my feelings, my mouth, my voice, all my actions, whether they be to others or myself. I own my fantasies, my dreams, my hopes, my fears. I own my triumphs and successes, all my failures and mistakes. Because I own all of me, I can become intimately acquainted with me. By so doing, I can love me and be friendly with all my parts. I know there are aspects about myself that puzzle me, and other aspects that I do not know -- but as long as I am friendly and loving to myself, I can courageously and hopefully look for solutions to the puzzles and ways to find out more about me. However I look and sound, whatever I say and do, and whatever I think and feel at a given moment in time is authentically me. If later some parts of how I looked, sounded, thought, and felt turn out to be unfitting, I can discard that which is unfitting, keep the rest, and invent something new for that which I discarded. I can see, hear, feel, think, say, and do. I have the tools to survive, to be close to others, to be productive, and to make sense and order out of the world of people and things outside of me. I own me, and therefore, I can engineer me. I am me, and I am Okay. I believe the single most significant decision I can make on a day-to-day basis is my choice of attitude. It is more important than my past, my education, my bankroll, my successes or failures, fame or pain, what other people think of me or say about me, my circumstances, or my position. Attitude keeps me going or cripples my progress. It alone fuels my fire or assaults my hope. When my attitudes are right, there is no barrier too high, no valley too deep, no dream too extreme, no challenge too great for me. What probably confuses people is they know a lot about me, but it quite pleases me that there's more they don't know.

Updated on July 28, 2022

Comments

  • Rafi Abro
    Rafi Abro almost 2 years

    When I perform any action it works in database but suddenly it shows an error of Database is Locked!

    Suppose this is the actionPerformed on one button:

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {       
    //Sahil_Computers.ConnecrDb(); is the database connecting method!                                  
        conn = Sahil_Computers.ConnecrDb();
        try{
          String sql = "insert into dailyExp (Sr,Description,Amount) values (?,?,?)";
          pst = conn.prepareStatement(sql);
          pst.setString(1, txt_srE.getText());
          pst.setString(2, txt_desE.getText());
          pst.setString(3, txt_rsE.getText());
    
          pst.execute();
          JOptionPane.showMessageDialog(null, "Saved!");
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }finally{
        try{
            rs.close();
            pst.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
    }    
      update_table_exp();
    }
    

    and then again when I try to perform another action just like:

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        conn = Sahil_Computers.ConnecrDb();
        String sql = "delete from dailySale where Sr=?";
        try{
            pst = conn.prepareStatement(sql);
            pst.setString(1, txt_sr1.getText());
            pst.execute();
            JOptionPane.showMessageDialog(null, "Deleted!");
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }finally{
        try{
            rs.close();
            pst.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
    }    
      update_table_sale();
    }
    

    or action like this one:

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        conn = Sahil_Computers.ConnecrDb();
        try{
            String sum = null, sub= null;
            String subto = null;
            int sum1, sub1, subto1;
            String sql = "select sum(Debit) from dailySale";
            pst=conn.prepareStatement(sql);
            rs=pst.executeQuery();
            if(rs.next()){
                sum = rs.getString("sum(Debit)");
                txt_tsale.setText(sum);
            }
            sql = "select sum(Amount) from dailyExp";
            pst=conn.prepareStatement(sql);
            rs=pst.executeQuery();
            if(rs.next()){
                sub = rs.getString("sum(Amount)");
                txt_texp.setText(sub);
            }
            sum1 = Integer.parseInt(sum);
            sub1 = Integer.parseInt(sub);
            subto1 = sum1 - sub1;
            subto = Integer.toString(subto1);
            txt_tsub.setText(subto);
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }finally{
        try{
            rs.close();
            pst.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }}}
    

    Then it shows database is locked!