This article is a mirror article of machine translation, please click here to jump to the original article.

View: 12307|Reply: 0

[Source] Spring MySQL common error solutions

[Copy link]
Posted on 1/15/2019 3:24:50 PM | | |
Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is 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. ### The error may exist in com/itsvse/es/mapper/AccountMapper.java (best guess) ### The error may involve com.itsvse.es.mapper.AccountMapper.findAllStudent ### The error occurred while executing a query ### Cause:


Solution:

After the connection string, append? serverTimezone=UTC
UTC is the Uniform Standard Universal Time.
Full connection string example: jdbc:mysql://localhost:3306/test?serverTimezone=UTC
Or there is another option: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8, this is to solve the Chinese garbled input problem, of course, it can also be combined with the above: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true& characterEncoding=UTF-8&serverTimezone=UTC



nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.



Solution:

The main reason is that in the process of configuring data sources in 1.0, the main ones are written: spring.datasource.url and spring.datasource.driverClassName.
After the 2.0 upgrade, you need to change it to: spring.datasource.jdbc-url and spring.datasource.driver-class-name to solve the problem!


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.


Solution:

com.mysql.jdbc.Driver is the one in mysql-connector-java 5,
com.mysql.cj.jdbc.Driver is in mysql-connector-java 6


You need to specify the time zone serverTimezone, when setting the time zone, if you set serverTimezone=UTC, it will be 8 hours ahead of China time, if you are in China, you can choose Asia/Shanghai or Asia/Hongkong, for example: jdbc:mysql://localhost:3306/test? serverTimezone=Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false






Previous:English Textbooks Longman packpack English textbooks
Next:Spring Boot uses Druid with the Property: spring.datasource.filters error
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com