title: JDBC driver - ClassNotFoundException, NetBeans
body: <p>I've searched a lot and spent many time trying register JDBC driver.</p>
  <p>First, I copied my ojdbc7.jar file (downloaded from Oracle) into directory shown below:</p>
  <pre><code>Driver File(s): /Users/Kamil/glassfish4/jdk7/jre/lib/ext/ojdbc7.jar
  Driver Class: oracle.jdbc.OracleDriver
  // this is copied from Services/Databases/Drivers/ojdbc
  </code></pre>
  <p>Then, I tried following code:</p>
  <pre><code>try {
      Driver myDriver = new oracle.jdbc.driver.OracleDriver();
      DriverManager.registerDriver(myDriver);
  } catch (ClassNotFoundException ex) {
      System.out.println(&quot;Error: unable to load driver class!&quot;);
      System.exit(1);
  }
  </code></pre>
  <p>... and this one:</p>
  <pre><code>try {
      Class.forName(&quot;oracle.jdbc.OracleDriver&quot;);
  } catch (ClassNotFoundException ex) {
      System.out.println(&quot;Error: unable to load driver class!&quot;);
      System.exit(1);
  }
  </code></pre>
  <p>... and with this line instead:</p>
  <pre><code>Class.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;);
  </code></pre>
  <p>I always get ClassNotFoundException :(</p>
  <p>Here is code I try to run:</p>
  <pre><code>Connection DBconn;
  String USER = &quot;root&quot;;
  String PASS = &quot;root&quot;;
  System.out.println(&quot;Connecting to database...&quot;);
  
  DBconn = DriverManager.getConnection(&quot;mysql://localhost:3306/RestToolDatabase&quot;, USER, PASS);
  
  System.out.println(&quot;Creating statement...&quot;);
  Statement stmt = DBconn.createStatement();
  String sql;
  sql = &quot;select surname, id, age\n&quot;
          + &quot;from customers \n&quot;
          + &quot;where name = \&quot;maria\&quot; \n&quot;
          + &quot;order by id;&quot;;
  ResultSet rs = stmt.executeQuery(sql);
  </code></pre>
  <p>I've also read about setting the classpath as described <a href="https://stackoverflow.com/questions/7598623/how-to-setup-classpath-in-netbeans">here</a>:</p>
  <ul>
  <li><p>Right-click your Project.</p>
  </li>
  <li><p>Select Properties.</p>
  </li>
  <li><p>On the left-hand side click Libraries.</p>
  </li>
  <li><p>Under Compile tab - click Add Jar/Folder button.</p>
  <p>but there is no &quot;Properties/Libraries&quot; option in NetBeans...</p>
  </li>
  </ul>
  <p>I use Maven and there is following dependency added by some library:</p>
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;ojdbc&lt;/groupId&gt;
      &lt;artifactId&gt;ojdbc&lt;/artifactId&gt;
      &lt;version&gt;14&lt;/version&gt;
      &lt;type&gt;pom&lt;/type&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>Maybe there is some workaround, or other way to add it automatically? It SHOULD be simple but I'm unexperienced and wasted many time on this. Please help.</p>
  <p><strong>EDIT</strong>: Thank you for replies, yes, I use MySQL Server at localhost:3306 [root]. I have MySQL JDBC connector installed here:</p>
  <pre><code>/Applications/NetBeans/NetBeans 8.0.app/Contents/Resources/NetBeans/ide/modules/ext/mysql-connector-java-5.1.23-bin.jar
  </code></pre>
  <p>When I go to &quot;Services&quot; --&gt; &quot;Drivers&quot; --&gt; &quot;MySQL (Connector/J driver)&quot; there is Driver Class path exactly as you suggested, so I use Class.forName(&quot;com.mysql.jdbc.Driver&quot;) now.
  I right-clicked on &quot;MySQL (Connector/J driver)&quot; driver and went to &quot;Connect Using...&quot; --&gt; &quot;localhost, port 3306, user, password&quot;. And it is connected now, I see new connection. But still I get ClassNotFoundException.</p>
  <h2><strong>EDIT 2 - this solution worked for me:</strong></h2>
  <p>I added following to dependencies in pom.xml:</p>
  <pre><code>    &lt;/dependency&gt;
          &lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
      &lt;version&gt;5.1.23&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>... and builded application; the driver was downloaded and installed. As simple as that... I spent many time on this... It works - yeah! :)</p>