MySQL JDBC Driver: mysql-connector-java vs mysql-connector-j
- Details
- Written by Nam Ha Minh
- Last Updated on 28 October 2023   |   Print Email
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:
- JDBC Driver Downloads
- JDBC Database Connection URLs
- How to connect to a database with JDBC
- JDBC CRUD Tutorial
- JDBC Transaction Tutorial
- How to call stored procedure with JDBC
- How to read database metadata in JDBC
- How to insert binary data into database with JDBC
- How to read binary data from database with JDBC
- How to use Scrollable ResultSet
- How to use Updatable ResultSet
- How to use CachedRowSet
Comments