While developing Java applications with Spring Boot and JDBC, you may get confused when you see there are two variants of MySQL JDBC driver: mysql-connector-java and mysql-connector-j. If Maven is used, the dependency declaration for the first one is:

<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<scope>runtime</scope>
</dependency>
And for the second one:

<dependency>
	<groupId>com.mysql</groupId>
	<artifactId>mysql-connector-j</artifactId>
	<scope>runtime</scope>
</dependency>
What’s the difference? Which one is correct? Which one should be used?

Well, the first one, mysql-connector-java was the original MySQL JDBC driver, but it doesn’t follow reverse-DNS convention of Maven with group Id is something like com.companyname and artifact Id is product/library name.

So recently, the MySQL JDBC driver library was changed to adopt Maven’s naming convention, with group Id is com.mysql and artifact Id is mysql-connector-j because the official name of MySQL JDBC driver is MySQL Connector/J. Hence the following dependency should be used:

<dependency>
	<groupId>com.mysql</groupId>
	<artifactId>mysql-connector-j</artifactId>
	<scope>runtime</scope>
</dependency>
  

MySQL JDBC driver with Spring Boot:

You know, Spring Boot defines default versions for common dependencies, including MySQL JDBC driver. That means if you upgrade your Spring Boot application to version 3.1 or newer, the following declaration won’t work:

<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
</dependency>
You will get the error saying that MySQL connector Java dependency version is missing. To fix, just use the new declaration:

<dependency>
	<groupId>com.mysql</groupId>
	<artifactId>mysql-connector-j</artifactId>
</dependency>
  

MySQL JDBC driver without Spring Boot:



If you use MySQL JDBC driver in non-Spring Boot application, you must specify dependency version so you can use either one. Both will work.

I hope this post has cleared your doubts about the differences between mysql-connector-java and mysql-connector-j, and now know which one should be used. You can also watch the video below:

 

Other JDBC Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment