title: JDBC for SQLite in Netbeans: No suitable driver found
body: <p>I need to load data from an SQLite file into a java program which I develop in Netbeans.
  The file is to be loaded via a swing menu item. I'm using <a href="https://bitbucket.org/xerial/sqlite-jdbc/downloads#tag-downloads" rel="nofollow">sqlitejdbc</a> as driver.  </p>
  
  <p>Here are the code blocks I assume to be important:</p>
  
  <pre><code>// header stuff
  package aufgabe_9;
  
  import java.sql.*;
  
  //...
  
  // menu item opening the file
  private void mitemOpenFileActionPerformed(java.awt.event.ActionEvent evt)  
  {                                              
  
      /**
       * Handles the dialogue for selecting and loading file.
       */
      JFileChooser fileChoose = new JFileChooser();
      fileChoose.showOpenDialog(this); //'this' calls the current object
  
       //Load the sql file
       try {
          String filePath = fileChoose.getSelectedFile().toString();
          Connection conn = DriverManager.getConnection("jdbc:sqlite:" +  
                      filePath);
  
          //Close the connection
          if (conn != null)
              conn.close();
  
      }
  
  
      catch (SQLException e){System.err.println("Database problem: " + e);}
      }                                  
  }
  
  //...
  </code></pre>
  
  <p>When running the program and loading a file via the menu, I get the following error:</p>
  
  <pre><code>java.sql.SQLException: No suitable driver found for jdbc:sqlite:/home/levent
  /temp/A9AProbeflaeche.db
  </code></pre>
  
  <p>After reading the respective stackexchange posts, I understand that this 
  problem can be caused by (1) a malformed file URL or (2) the driver not being
  loaded. Here's some further information:</p>
  
  <ul>
  <li>I added the sqlitejdbc-3.7.2.jar to the library classpath via <em>Tools --> Libraries</em> as well as to the project libraries via <em>Window --> Projects</em>.</li>
  <li>I also checked the <em>Classpath</em> by using <a href="http://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/" rel="nofollow">this function</a>. It contains the path to the jdbc jar-file just as expected.</li>
  <li>I can connect to the database via the <em>Services</em> menu without any problems, so I can assume the URL to be correct, as well as sqlite running on my system.</li>
  <li>Some OS information: I'm running Netbeans 8.0 on 64 bit ARCH Linux 3.12.9-2.</li>
  </ul>
  
  <p>Can anybody tell me what I'm missing here? Any help appreciated!</p>
  
  <p><strong>Problem solved</strong>
  Here is the code that works for me:</p>
  
  <pre><code>//...
  private void mitemOpenFileActionPerformed(java.awt.event.ActionEvent evt)   
  {                                              
  
      /**
      * Handles the dialogue for selecting and loading file.
      */
      JFileChooser fileChoose = new JFileChooser();
      fileChoose.showOpenDialog(this); 
  
      //Load the sql file
      try {
          //Get file path
          String filePath = fileChoose.getSelectedFile().toString();
  
          //Open connection
          Class.forName("org.sqlite.JDBC");
          Connection conn = DriverManager.getConnection("jdbc:sqlite:" + filePath);
  
          //Do stuff...                       
  
          //Close the connection
          conn.close();
  
      }
  
      //"Multicatch":
      catch (SQLException | ClassNotFoundException e) { 
      System.err.println("Database problem: " + e);
  }
  //...
  </code></pre>