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

這裏只是配置文件做了一些修改。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章