Languages
[Edit]
EN

Java - how to load MySQL JDBC driver proper way?

14 points
Created by:
Jax
388

Working with MySQL and JDBC in Java requires to make some steps depending of driver version we work.

Universal steps:

  1. download JDBC driver visit maven repository web page select some version and download *.jar file,
  2. attach *.jar file to your project as library,
  3. load "com.mysql.jdbc.Driver" or "com.mysql.cj.jdbc.Driver" with Class.forName() method call if it is necessary.

Below fast descriptions how to load drivers have been described.

1. How to recognize, if we have new or old one driver?

Edit

If bellow message will appear in console it means we have new driver.

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

Read more about version with API changes here.

2. New JDBC driver loading way example

Edit

If projects uses the newest vesion of JDBC, this approach should be used.

Result:

Note: data preparation sql can be found here (at the end of article).

3. Old JDBC driver loading way example

Edit

Result:

Note: data preparation sql can be found here (at the end of article).

Alternative titles

  1. Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI ...
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - MySQL

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join