Nataliya Nataliya - 6 months ago 10
SQL Question

Class not Found: com.mysql.jdbc.Driver

Trying to print

books
database content and I receive the following error:
java.lang.ClassNotFoundException
.

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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at jdbc.JDBCConnector.main(JDBCConnector.java:22)
The end!


What was done:


  • mysql-connector jar file has been added already. Screenshot from Eclipse

  • I've also tried different versions to import:
    mysql-connector-java-5.1.39
    and
    mysql-connector-java-5.0.8

  • I tried to use both:
    jdbc:mysql://localhost/books
    as well as
    jdbc:mysql://localhost:3306/books
    as the database URL



I would be really glad if someone could help me to clarify this issue.

Answer

You added the zip into your classpath instead of the jar that is the reason why, put only mysql-connection-java-4.1.39-bin.jar into your classpath.