1

I'm writing JDBC code in which I have this import:

import com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException;

While executing I'm getting:

java.lang.ClassNotFoundException: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException

Though I have already added the mysql.jar in class path. Any solution for this? Do I have to add any other jar file for this class?

1
  • 1
    Since your code compiled, the class obviously existed in the classpath at compile-time. It would seem that you didn't include the .jar file in the classpath at runtime. Commented Jul 31, 2017 at 20:11

2 Answers 2

2

I found this error while upgrading my JDBC connection JAR file to mysql-connector-java-8.0.21.jar

And realised that package name is changed from com.mysql.jdbc.exceptions.* to java.sql.*

May be this will help you, if you replace

import com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException;

with

import java.sql.SQLIntegrityConstraintViolationException

May this help you to understand, if you have the similar issue: JAVA: cannot find symbol PreparedStatement (JAR Upgrade)

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

Comments

-1

"java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" is NOT a compilation error. The solution is to make sure that the JAR file is on the classpath when you run the application.

If you're using Eclipse, follow below points

  1. Right click your project folder and open up Properties.

  2. From the right panel, select Java Build Path then go to Libraries tab.

  3. Select Add External JARs to import the mysql driver.

  4. From the right panel, select Deployment Assembly.

  5. Select Add..., then select Java Build Path Entries and click Next.

  6. You should see the sql driver on the list. Select it and click first.

1 Comment

This doesn't address the problem of the question, or at least, "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" is NOT a compilation error indicates you haven't tailored your answer to the actual question.

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.