异常内容:
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:897) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:822) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:447) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:237) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at org.javaboy.vhr.utils.JdbcUtil.<init>(JdbcUtil.java:26) at org.javaboy.vhr.utils.MybatisGeneratorUtil.generator(MybatisGeneratorUtil.java:81) at org.javaboy.vhr.utils.Generator.main(Generator.java:34) 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. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85) at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132) at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2139) at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2163) at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1301) at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:860) ... 9 more解决方案:
抛异常的jdbc.url配置为:
jdbc.url=jdbc:mysql://localhost:3306/vhr?useUnicode\=true&characterEncoding\=utf-8&autoReconnect\=true改成下面的配置:
jdbc.url=jdbc:mysql://localhost:3306/vhr?useUnicode\=true&characterEncoding\=utf-8&autoReconnect\=true&serverTimezone\=Asia/Shanghai