首页

解决生成代码提示“Loading class com.mysql.jdbc.Driver. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver”错误

标签:SQLException     发布时间:2023-07-26   

一、错误描述

点击mybatis-generator代码生成报“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.”错误。

F:\BaiduNetdiskDownload\generator>generatorCode.bat@b@F:\BaiduNetdiskDownload\generator>java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite@b@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.@b@java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.@b@        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)@b@        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)@b@        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)@b@        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)@b@        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)@b@        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)@b@        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)@b@        at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)@b@        at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)@b@        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)@b@        at org.mybatis.generator.internal.db.ConnectionFactory.getConnection(ConnectionFactory.java:68)@b@        at org.mybatis.generator.config.Context.getConnection(Context.java:526)@b@        at org.mybatis.generator.config.Context.introspectTables(Context.java:436)@b@        at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:222)@b@        at org.mybatis.generator.api.ShellRunner.main(ShellRunner.java:117)@b@Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.@b@        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)@b@        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)@b@        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)@b@        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)@b@        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)@b@        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)@b@        at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)@b@        at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2234)@b@        at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2258)@b@        at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319)@b@        at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:966)@b@        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)@b@        ... 8 more

二、解决方法

修改generator.xml文件内容 - com.mysql.cj.jdbc.Driver替换com.mysql.jdbc.Driver数据库mysql驱动配置,如下所示

<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/localtest" userId="root" password="123456">

改为

<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/localtest?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone=GMT" userId="root" password="123456">
@b@
<<推荐下载>>