title: Java and SQLite: avoid database locking errors
body: <h2>Scenario:</h2>
  
  <p>I am trying to write a program that can read and write to an SQLite database. The application can be opened by multiple computers connected by a network/shared folder with the db file (so that multiple people can add/read the data at once). </p>
  
  <h2>Problem:</h2>
  
  <p>Whenever I try to edit the database with more than 1 window open, the 'database is locked' error inevitably comes up (they can simultaneously read it fine). I am closing every resultSet as soon as possible but the connection is kept open the whole time. </p>
  
  <p>So essentially, I would like to know when the database is locked/unlocked, and if it is possible to only lock the database when updating and unlock it at other times.</p>
  
  <p>My code to connect to the database is:</p>
  
  <pre><code>    try {
          //Create and/or connect to the database
          Class.forName("org.sqlite.JDBC");
          //c is a global Connection variable
          c = DriverManager.getConnection("jdbc:sqlite:" + dbLocation);
          c.setAutoCommit(false);
      } 
      catch ( Exception e ) { 
          //print the error message if there is an exception
          System.err.println( e.getClass().getName() + ": " + e.getMessage() );
          System.exit(0);
      }
  </code></pre>
  
  <p>The connection is maintained throughout the time the application is run and closed <code>c.close();</code> when the application interface is closed </p>
  
  <p>Thanks :)</p>