Recently I have been working on a Java Web Application with JDBC and I have found that com.mysql.jdbc.Driver
is deprecated since "Connector/J API 8.0".
Therefore as shown below, the Java Runtime warns you to use com.mysql.cj.jdbc.Driver
, instead of using the deprecated 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.
What my problem is really lies under this line.
The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
At first, I have thought this means it is not required to call Class.forName
to register the driver, but after testing out, I have found that I was wrong.
So what is actually mean by manual loading of the driver class is generally unnecessary
? Is there something that I have missed?
Thank you.
The MySQL Connector/J developer guide is still referring to the Class.forName. See https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-connect-drivermanager.html
But starting with JDBC 4, the Service Provider Interface is used, so the call should no longer be required. (And for me it works without the Class.forName call!)
Details about the SPI: