Note that there are some explanatory texts on larger screens.

plurals
  1. POJava MySQL Driver and ClassNotFoundException
    primarykey
    data
    text
    <p>I am attempting to connect to a mysql database, with a connection url of:</p> <pre><code>jdbc:mysql://127.0.0.1:3306/test </code></pre> <p>I have downloaded the coorect Mysql driver to connect with the database, and have tried a multitude of approaches to set the driver, with each not working. So far I have tried placing the JAR file in the following places (and changing the PATH environment variable accordingly)</p> <pre><code>JRE/LIB/ JDK/LIB/ JRE/LIB/mysql-connector-java-5.1.21 JDK/LIB/mysql-connector-java-5.1.21 </code></pre> <p>The path for the JAR file has been its location + <code>mysql-connector-java-5.1.21-bin.jar</code></p> <p>Over the last 4+ hours I have read multiple questions and solutions on StackOverflow, as well as online tutorials about this issue, and none have solved the problem. </p> <p>I have been using the following code to attempt a connection</p> <pre><code>import java.sql.*; import java.util.Date; public class DatabaseHelper{ private Connection conn = null; private Statement statement = null; private PreparedStatement preparedStatement = null; private ResultSet resultSet = null; private String url = null; public DatabaseHelper(){ try{ Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test"); System.out.println("Driver Loaded!"); }catch(SQLException e){ e.printStackTrace(); }catch(ClassNotFoundException e){ e.printStackTrace(); } } } </code></pre> <p>Stacktrace</p> <pre><code>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:186) at DatabaseHelper.&lt;init&gt;(DatabaseHelper.java:28) at DatabaseTest.&lt;init&gt;(DatabaseTest.java:6) at DatabaseTest.main(DatabaseTest.java:14) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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