Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to install JDBC driver in Eclipse web project without facing java.lang.ClassNotFoundexception
    text
    copied!<p><a href="https://stackoverflow.com/questions/1585811/classnotfoundexception-com-mysql-jdbc-driver">There is a VERY similar question</a> to mine but in my case I don't have any duplicate jars in my build path, so the solution does not work for me. I've searched google for a couple of hours now, but none of the solutions I've found there actually resolve my issue. I'm creating a web site with some database connectivity for a homework. I'm using a MySQL database, developing in Eclipse and running on Windows.</p> <p>I keep getting <code>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver</code> with the following code:</p> <pre><code>import java.sql.*; //... public void someMethodInMyServlet(PrintWriter out) { Connection connection = null; PreparedStatement query = null; try { out.println("Create the driver instance.&lt;br&gt;"); Class.forName("com.mysql.jdbc.Driver").newInstance(); out.println("Get the connection.&lt;br&gt;"); connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "secret"); query = connection.prepareStatement( "SELECT * FROM customers"); //... } catch (Exception e) { out.println(e.toString()+"&lt;br&gt;"); } } //... </code></pre> <p>When I run the above code I get the following output:</p> <pre><code>Create the driver instance. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver </code></pre> <p>It doesn't get past the <code>Class.forName...</code> line and I can't figure out why! Here is what I did: </p> <ol> <li>Download mysql-connector. </li> <li>Put it in my MySQL folder <code>C:\Program Files\MySQL\mysql-connector-java-5.1.12\mysql-connector-java-5.1.12-bin.jar</code>. </li> <li>Opened the project properties in Eclipse. </li> <li>Add External Jar to my Build Path and I selected <code>mysql-connector-java-5.1.12-bin.jar</code>.</li> </ol> <p>Every time I attempt to use the servlet I get the same error regardless if I have the jar in there or if I don't. Could you help me figure this out?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload