user3880721
user3880721

Reputation: 613

MySQL JDBC driver error

I keep getting

Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at ttest.Sql.readFile(Sql.java:28)
at ttest.Sql.main(Sql.java:68)

to

Class.forName("com.mysql.jdbc.Driver"); 

on NetBeans and can't see why!

MySQL is running fine with JPA.

Do i need additional settings for JDBC?

burnt so much of my time!!

TIA

Upvotes: 1

Views: 5343

Answers (3)

hasith wijerathna
hasith wijerathna

Reputation: 21

Copy mysql-connector-java-5.1.34-bin.jar (it is in the C:\Program Files\MySQL\Connector.J 5.1) into C:\Program Files\Java\jdk1.7.0\jre\lib\ext

Upvotes: 1

Prazzy Kumar
Prazzy Kumar

Reputation: 994

MySQL connector is already present in Netbeans, you just have to import that into your project. Follow the given STeps

  1. Click project properties
  2. Click on libraries and then Add Library
  3. Click on import ,then you will see many jars available
  4. Select the Mysql JDBC driver and import it.

Thats it. Now try running your project.

Upvotes: 0

Darshan Lila
Darshan Lila

Reputation: 5868

You would need MYSQL connector in your class path to connect to MySql database from JDBC. You ca get one from here.

Upvotes: 2

Related Questions