ssm的报错问题------You must configure either the server or JDBC driver (via the serverTimezone conf)
在測試MySQL數(shù)據(jù)庫連接的過程中,產(chǎn)生的問題。(在ssm項(xiàng)目環(huán)境下進(jìn)行測試,使用idea編輯器其):
測試MySQL數(shù)據(jù)庫是否連接成功博客:在spring項(xiàng)目中,測試MySQL數(shù)據(jù)庫是否連接成功_qq_41818544的博客-CSDN博客
報錯信息:
Fri May 17 14:55:39 CST 2019 There was an unexpected error (type=Internal Server Error, status=500). nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLSyntaxErrorException: Identifier name 'netsafe&useunicode=true&characterencoding=utf-8&allowmultiqueries=true&usessl=false' is too long ### The error may exist in com/infosec/netsafess/mapper/UserMapper.java (best guess) ### The error may involve com.infosec.netsafess.mapper.UserMapper.getAllUser ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLSyntaxErrorException: Identifier name 'netsafe&useunicode=true&characterencoding=utf-8&allowmultiqueries=true&usessl=false' is too long org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLSyntaxErrorException: Identifier name 'netsafe&useunicode=true&characterencoding=utf-8&allowmultiqueries=true&usessl=false' is too long ### The error may exist in com/infosec/netsafess/mapper/UserMapper.java (best guess) ### The error may involve com.infosec.netsafess.mapper.UserMapper.getAllUser ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLSyntaxErrorException: Identifier name 'netsafe&useunicode=true&characterencoding=utf-8&allowmultiqueries=true&usessl=false' is too longat org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)at com.sun.proxy.$Proxy60.selectList(Unknown Source)at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)at com.sun.proxy.$Proxy64.getAllUser(Unknown Source)at com.infosec.netsafess.service.impl.UserServiceImpl.getAllUser(UserServiceImpl.java:19)at com.infosec.netsafess.controller.HelloController.getAllUser(HelloController.java:25)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)啟動springboot項(xiàng)目,然后訪問數(shù)據(jù)庫,報You must configure either the server or JDBC driver (via the serverTimezone conf)的錯誤。
原因:
因?yàn)榘惭bmysql的時候時區(qū)設(shè)置的不正確 mysql默認(rèn)的是美國的時區(qū),而我們中國大陸要比他們遲8小時,采用+8:00格式
使用的數(shù)據(jù)庫是MySQL,從上面圖看出SpringBoot2.1在你沒有指定MySQL驅(qū)動版本的情況下它自動依賴的驅(qū)動是8.0.12很高的版本,這是由于數(shù)據(jù)庫和系統(tǒng)時區(qū)差異所造成的,在jdbc連接的url后面加上serverTimezone=GMT即可解決問題,如果需要使用gmt+8時區(qū),需要寫成GMT%2B8,否則會被解析為空。再一個解決辦法就是使用低版本的MySQL jdbc驅(qū)動,5.1.28不會存在時區(qū)的問題。
加上這個 ??serverTimezone=UTC?
spring.datasource.url=jdbc:mysql://localhost:3306/blog?serverTimezone=UTC
例如:
?
總結(jié)
以上是生活随笔為你收集整理的ssm的报错问题------You must configure either the server or JDBC driver (via the serverTimezone conf)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 最大子段和(动态规划及分治法)
- 下一篇: 粒子群算法参数w的改进