首页

解决生成代码提示“java.sql.SQLException: The server time zone value ???ú±ê×??±?? is unrecognized or represents more than one time zone”错误

标签:serverTimezone,区域GMT     发布时间:2023-07-26   

一、错误描述

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

F:\BaiduNetdiskDownload\generator>generatorCode.bat@b@@b@F:\BaiduNetdiskDownload\generator>java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite@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的配置,将连接串添加区域配置“serverTimezone=GMT”

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

改为

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




<<热门下载>>