打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
You must configure either the server or JDBC driver (via the serverTimezone conf)
serverTimezone=UTC今天在用SpringBoot(v2.1.6.RELEASE)+MyBatis+MySQL搭建项目开发环境的时候启动项目发现报了一个很奇怪的错,报错内容如下:
  1. Fri May 17 14:55:39 CST 2019
  2. There was an unexpected error (type=Internal Server Error, status=500).
  3. 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
  4. org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
  5. ### 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
  6. ### The error may exist in com/infosec/netsafess/mapper/UserMapper.java (best guess)
  7. ### The error may involve com.infosec.netsafess.mapper.UserMapper.getAllUser
  8. ### The error occurred while executing a query
  9. ### 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
  10. at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
  11. at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
  12. at com.sun.proxy.$Proxy60.selectList(Unknown Source)
  13. at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
  14. at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
  15. at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
  16. at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
  17. at com.sun.proxy.$Proxy64.getAllUser(Unknown Source)
  18. at com.infosec.netsafess.service.impl.UserServiceImpl.getAllUser(UserServiceImpl.java:19)
  19. at com.infosec.netsafess.controller.HelloController.getAllUser(HelloController.java:25)
  20. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  21. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  22. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

启动springboot项目,然后访问数据库,报You must configure either the server or JDBC driver (via the serverTimezone conf)的错误,原因

因为安装mysql的时候时区设置的不正确 mysql默认的是美国的时区,而我们中国大陆要比他们迟8小时,采用+8:00格式

 

使用的数据库是MySQL,从上面图看出SpringBoot2.1在你没有指定MySQL驱动版本的情况下它自动依赖的驱动是8.0.12很高的版本,这是由于数据库和系统时区差异所造成的,在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8,否则会被解析为空。再一个解决办法就是使用低版本的MySQL jdbc驱动,5.1.28不会存在时区的问题。

加上这个  ?serverTimezone=UTC 

spring.datasource.url=jdbc:mysql://localhost:3306/exam?serverTimezone=UTC

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
ibatis 打印SQL语句
MyBatis Batch Update Exception
Mapped Statements collection does not contain value for
log4j配置打印mybatis sql语句
Junit测试mybatis-只是个示例-有基础的入
SpringBoot整合MyBatis
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服