Spring Boot学习笔记之使用Spring Boots实现数据库操作(IntelliJ IDEA+MySQL)

Spring Boot学习笔记之使用Spring Boots实现数据库操作已经写过一篇:https://blog.csdn.net/wangruoao/article/details/83015083

这里跟连接SQL server数据库的时候相比,只修改配置文件application.properties即可:

server.port=8081

#数据库用户名密码设置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test
spring.datasource.username=root
spring.datasource.password=123456

但是启动App的时候一直报错:MySQL的时候遇到了一个问题:

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) ~[na:1.8.0_181]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_181]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_181]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_181]
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59) ~[mysql-connector-java-8.0.11.jar:8.0.11]

 

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

后来发现是因为MySQL版本的问题,可能会有以上的错误,在“spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test”后面加上“?serverTimezone=GMT%2B8”,设置下时区。则解决了上面的问题。

server.port=8081

#数据库用户名密码设置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123456

这里只是配置文件做了一些修改。

 

 

你可能感兴趣的:(Spring,Boot学习)