0

Whenever I execute my code for accessing a database I get the following error:

:java.lang.ClassNotFoundException: com.mysql.jdbc.DriverError :java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

2
  • See stackoverflow.com/questions/4835640/… Commented Feb 8, 2011 at 14:35
  • The exception in question is thrown because the mysql connector is not in the execution class path. check the accepted answer on the question referred to by Yasir (above this comment). Accept some answers. Commented Feb 8, 2011 at 15:23

3 Answers 3

1

You don't have the mysql connector added to your project. See this page for more information: http://dev.mysql.com/usingmysql/java/1

Edit:

If you are using netbeans, just right click on the library folder of your project, and then select the option 'add library'. You will find the 'MySQL JDBC Driver' library, select this library and click on 'Add library'.

Sign up to request clarification or add additional context in comments.

1 Comment

There is no "project" in Java. Your IDE might know of that concept, but Java doesn't. You need to have the JDBC driver on your classpath. You should know the underlying concepts in Java and not just depend on your IDE.
0

You have to add the driver you mentioned in your classpath. If you're using maven then you need to include the following dependency in your POM file.

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.14</version>
  <scope>runtime</scope>
</dependency>

Otherwise you have to download manually the Connector J from http://dev.mysql.com/downloads/mirror.php?id=13597#mirrors

Comments

0

This blog may be helpful: SuaveSnippets: JDBC and MySQL, ClassNOTFoundException

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.