0

Recently I was working with JDBC, and all code which uses JDBC were working perfectly.

After some time I started using JDBC again to refresh all concepts. The problem is, when I wrote my new program at that time, it gave me ClassNotFoundException. Everything in my code was perfect. I also added the external JAR file of the MySQL connector. The exception was ClassNotFoundException com.mysql.jdbc.Driver.

I tried different IDEs to run that code, but it gave me the same error. But then I tried to import this MySQL connector from the Maven repository and all the exceptions were cleared and executed perfectly.

Previously I was using this MySQL connector. Also both connectors versions were the same which was 8.0.11. I have really less amount of knowledge of Maven.

Why did the MySQL connector JAR file from Maven work perfectly and the other didn't?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Under_stand
  • 69
  • 1
  • 10

1 Answers1

1

Based on what you've said, it sounds like your manually-imported JAR file didn't import for one reason or another. The Maven import was successful and everything clicked.

The other thing that's possible is that you're using a different version of the MySQL JDBC driver.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JWilliams
  • 128
  • 6
  • Both connectors version was same which was 8.0.11.I also tried mysql-connector-java-5.1.46 but the result was same.But connector 8.0.11 from maven worked. – Under_stand Jun 11 '18 at 19:32
  • 1
    So you didn't deploy the other one properly. The error message is quite clear. The class was not found. That's not a problem with that JAR file: this is a problem caused by the *absence* of that JAR file. – user207421 Jun 11 '18 at 22:58
  • @EJP But the jar file was added succesfully and issue was still there. – Under_stand Jun 12 '18 at 11:08
  • @Under_stand you might have added the jar but its not in your classpath. – JWilliams Jun 12 '18 at 23:10
  • I have figured out the solution.I was importing zip file which contains jar file and other stuff.When i imported the jar file only which is inside of that zip all the things worked.In future should i need to import that specific jar file only rather than zip file which contains that jar file? – Under_stand Jun 14 '18 at 11:36
  • 1
    @Under_Stand that is correct, Java will not extract zip files looking for libraries. If my answer helped you I'd appreciate if you could select my answer as correct. – JWilliams Jun 15 '18 at 22:24