title: SQLITE_BUSY the database is locked java
body: <p>I have create a java software which make use of sqlite database. The whole database works smoothly however after some time of running the application I am reveiving the following message (from a try catch block):</p>
  
  <blockquote>
    <p>java.sql.SQLException: [SQLITE_BUSY]  The database file is locked (database is locked)</p>
  </blockquote>
  
  <p>I ve solved my problems by closing the software every time the exception rising. However is there a way to close my database instead so as not to close the software every time? </p>
  
  <p>I ve got plenty of queries however my prob arises always in a specific point:</p>
  
  <pre><code>        try {
              String query = "select * from StudentsSession where userId=? and course=? and level=?";
              PreparedStatement pst = connectionUsers.prepareStatement(query);
              pst.setString(1, saveUser.getText());
              pst.setString(2, textSubjectQTest);
              st.setString(3, showCurrentLevelLabel.getText());
              ResultSet rs = pst.executeQuery();
              while (rs.next()) {
                  count = count + 1;
              }
              pst.close();
              rs.close();
  
          } catch (Exception a) {
              System.out.println(a);
          }
          try {
              String countS, tmpS;
              countS = String.valueOf(count);
              sessionId.setText(countS);
              long unixTime = System.currentTimeMillis() / 1000L;
              tmpS = String.valueOf(unixTime);
              date.setText(tmpS);
              course.setText(textSubjectQTest);
  
              String query = "insert into StudentsSession (userId,date,course,level,trial,score) values (?,?,?,?,?,-1)";
              PreparedStatement pst = connectionUsers.prepareStatement(query);
              pst.setString(1, saveUser.getText());
              pst.setString(2, tmpS);
              pst.setString(3, textSubjectQTest);
              pst.setString(4, showCurrentLevelLabel.getText());
              pst.setString(5, countS);
              pst.executeUpdate();
              pst.close();
  
          } catch (Exception a) {
  
              System.out.println(a);
              System.exit(0);
          }
  
          String file1 = "";
          ResultSet ts4;
          try {
  
              sessionId3 = "";
              String query3 = "select * from studentssession where userid = ?  and course = ? and level = ?";
              PreparedStatement pst__1 = connectionUsers.prepareStatement(query3);
              pst__1.setString(1, saveUser.getText());
              pst__1.setString(2, textSubjectQTest);
              pst__1.setString(3, showCurrentLevelLabel.getText());
              ts4 = pst__1.executeQuery();
  
              while (ts4.next()) {
                  sessionId3 = ts4.getString("sessionId");
              }
              pst__1.close();
              ts4.close();
              obj = new CaptureVideoFromWebCamera();
  
              file1 = "videos/" + userTextFieldS.getText();
  
              file1 = file1 + "_" + sessionId3;
              file1 = file1 + ".wmv";
  
              obj.start(file1);
  
          } catch (Exception e4) {
              e4.getCause();
          }
  </code></pre>
  
  <p>Sometimes this code rise the exception.</p>