How to Solve Error Message : Loading class `com.mysql.jdbc.Driver’. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver’.

Posted on

Eventually, the focus of this article is specifically discuss about how to load the correct or the suitable driver of MySQL Database Connection. There is an error retrieved from the server.log located inside the installation folder of Wildfly Java Application Server. Precisely, in the context of this article where the installation folder specified is in ‘/opt/wildfly-12.0.0.Final’, it is stored in a folder named log as shown in the following directory structure :

user@hostname:/opt/wildfly-12.0.0.Final$ tree -L 3
.
├── appclient
│   └── configuration
│       ├── appclient.xml
│       └── logging.properties
├── bin
...
│   ├── appclient.sh
│   ├── client
...
│   │   └── README-EJB-JMS.txt
...
│   └── wsprovide.sh
├── copyright.txt
├── docs
│   ├── contrib
│   │   └── scripts
│   ├── examples
...
│   │   └── enable-elytron.cli
│   ├── licenses
...
│   │   └── the jsoup mit license.html
│   └── schema
...
│       └── xnio_3_5.xsd
├── domain
│   ├── configuration
│   │   ├── application-roles.properties
│   │   ├── application-users.properties
│   │   ├── default-server-logging.properties
│   │   ├── domain.xml
│   │   ├── host-master.xml
│   │   ├── host-slave.xml
│   │   ├── host.xml
│   │   ├── logging.properties
│   │   ├── mgmt-groups.properties
│   │   └── mgmt-users.properties
│   ├── data
│   │   └── content
│   └── tmp
│       └── auth
├── jboss-modules.jar
├── LICENSE.txt
├── modules
│   ├── com
│   │   └── mysql
│   └── system
│       └── layers
├── nohup.out
├── README.txt
├── standalone
│   ├── configuration
...
│   │   └── standalone_xml_history
│   ├── data
...
│   │   └── tx-object-store
│   ├── deployments
...
│   │   ├── webapp.war
│   │   └── webapp.war.deployed
│   ├── lib
│   │   └── ext
│   ├── log
│   │   ├── audit.log
│   │   ├── server.log
...
│   └── tmp
│       ├── auth
│       ├── startup-marker
│       ├── webapp-1.0-SNAPSHOT.war
│       ├── vfs
│       └── webapp.war
└── welcome-content
...
    └── wildfly_logo.png

43 directories, 472 files
user@hostname:/opt/wildfly-12.0.0.Final$ 

The file itself is named ‘server.log’ as shown in the above directory structure, precisely in the’/opt/wildfly-12.0.0.Final/standalone/logs’. Below is the content of the directory where the log file available :

user@hostname:/opt/wildfly-12.0.0.Final/standalone$ cd log/
user@hostname:/opt/wildfly-12.0.0.Final/standalone/log$ ls
audit.log   server.log.2018-05-08  server.log.2018-06-09  server.log.2018-06-11  server.log.2018-06-13  server.log.2018-06-15  server.log.2018-06-17
server.log  server.log.2018-06-05  server.log.2018-06-10  server.log.2018-06-12  server.log.2018-06-14  server.log.2018-06-16
user@hostname:/opt/wildfly-12.0.0.Final/standalone/log$ pwd
/opt/wildfly-12.0.0.Final/standalone/log
user@hostname:/opt/wildfly-12.0.0.Final/standalone/log$ ls -al | grep server.log
-rw-rw-r-- 1 user user 21868165 Jun 18 23:09 server.log
...
user@hostname:/opt/wildfly-12.0.0.Final/standalone/log$ 

Below is the actual line pointed out the error in the server.log file :

22:01:37,430 INFO [org.jboss.as.connector] (MSC service thread 1-3) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.4.7.Final)
22:01:37,432 ERROR [stderr] (ServerService Thread Pool -- 36) 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.
22:01:37,434 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0018: Started Driver

Based on the information in the error log retrieved above, the driver name which is usually used,’com.mysql.jdbc.Driver’ is deprecated. It must be replaced with a new one named ‘com.mysql.cj.jdbc.Driver’. Well, the information can also be retrieved from the official MySQL Website as shown below :

How to Solve Error Message : Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.
How to Solve Error Message : Loading class `com.mysql.jdbc.Driver’. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver’.

So, to solve the problem,just change the name of the driver where it can be edited in the configuration file of Wildfly as located in ‘/opt/wildfly-12.0.0.Final/standalone/configuration/standalone.xml’ :

<driver name="mysql" module="com.mysql">
<driver-class>com.mysql.cj.jdbc.Driver</driver-class>
</driver>

Don’t forget to shutdown and start the Wildfly Java Application Server so that the change of the configuration can be implemented. For more information about loading the MySQL Database Driver, just read the article titled ‘How to Load MySQL Database Driver in Wildfly Java Application Server’ in this link and also another article related with the title of ‘How to Solve Wildfy Error Message : WFLYJCA0041: Failed to load module for driver [com.mysql]’ in this link.

One thought on “How to Solve Error Message : Loading class `com.mysql.jdbc.Driver’. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver’.

Leave a Reply