title: JAVA: sqlite throws exception after writing a few records?
body: <p>I am trying to write a few thousand records to sqlite DB. However after writing a random number of records - 122 / 45 / 180, it throws following exception:</p>
  
  <pre><code>java.sql.SQLException: unable to open database file
  </code></pre>
  
  <p>The random number of records get populated on DB but this error stops further record writing. What am I doing wrong?</p>
  
  <p>EDIT:</p>
  
  <pre><code>Class loginModel:
  
  private connection;
  
  public loginModel(){
          connection = SqLiteConnection.connector();
          if(connection == null)
              System.exit(1);
      }
  
  public boolean interactWithDB() throws SQLException{
  
      PreparedStatement preparedStatement = null;
      ResultSet resultSet = null;
  
      String query;
  
      try {
          query = "";
          DBPopulator dbPopulator = new DBPopulator();
          dbPopulator.populateData();
          List&lt;dbData&gt; dataList = dbPopulator.getdbData();
          Iterator&lt;dbData&gt; it = dataList.listIterator(); 
          while(it.hasNext()){
              dbData data = it.next();
              query = getNewInsertQuery(data); // builds query based on data input
              preparedStatement = connection.prepareStatement(query);
              preparedStatement.executeUpdate();  
          }                   
          return true;
      } catch (Exception e) {
          // TODO: handle exception
          System.out.println(e);
          return false;
      }
      finally{
          if(preparedStatement!=null)
              preparedStatement.close();
          if(resultSet!=null)
              resultSet.close();
          connection.close();
      }
  }
  </code></pre>
  
  <p>And I am getting the new connection through: </p>
  
  <p>Class: SqLiteConnection</p>
  
  <pre><code>public static Connection connector(){
      try{
          Class.forName("org.sqlite.JDBC");           
          Connection conn = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\akshaysu\\Documents\\r_sqlite.sqlite");
          conn.setAutoCommit(true);
          return conn;
      }       
      catch(Exception e){
          System.out.println("DB not found");
          System.out.println(e);
          return null;
      }
  }
  </code></pre>
  
  <p>EXCEPTION:</p>
  
  <pre><code>java.sql.SQLException: unable to open database file
      at org.sqlite.DB.execute(DB.java:275)
      at org.sqlite.DB.executeUpdate(DB.java:281)
      at org.sqlite.PrepStmt.executeUpdate(PrepStmt.java:77)
      at application.loginModel.interactWithDB(loginModel.java:98)
      at application.loginController.buttonAction(loginController.java:30)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at sun.reflect.misc.Trampoline.invoke(Unknown Source)
      at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
      at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
      at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
      at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
      at javafx.event.Event.fireEvent(Unknown Source)
      at javafx.scene.Node.fireEvent(Unknown Source)
      at javafx.scene.control.Button.fire(Unknown Source)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
      at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
      at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
      at javafx.event.Event.fireEvent(Unknown Source)
      at javafx.scene.Scene$MouseHandler.process(Unknown Source)
      at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
      at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$355(Unknown Source)
      at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
      at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
      at com.sun.glass.ui.View.notifyMouse(Unknown Source)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>EDIT3:</p>
  
  <pre><code>private String getNewInsertQuery(dbData e){
          String query = "";
          query = "insert into r_sqlite (NAME, AGE, COMPANY-NAME) VALUES(";
          query += e.getName()+", ";
          query += e.getAge()+", ";
          query += e.getCompany();
          query += ");";      
          return query;
          }
  </code></pre>