java报错Cause: java.sql.SQLException问题解决

 更新时间:2023年08月29日 10:07:16   作者:大米宋  
本文主要介绍了java报错Cause: java.sql.SQLException问题解决,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

问题描述:

Cause: 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.

持久化异常原因:java.sql.SQLException:服务器时区值’ й׼ʱ’无法识别或代表多个时区。 如果希望利用时区支持,则必须(通过serverTimezone配置属性)配置服务器或JDBC驱动程序,以使用更特定的时区值。

image-20220725102717827

报错原因:

这是jdbc连接url路径里面没有加时区;

解决办法:

mybatis.config.xml文件中url加入:

serverTimezone=Asia/Shanghai
<!--dataSource数据源-->
<dataSource type="POOLED">
    <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
    <!--useSSL=true:就是一般通过证书或者令牌进行安全验证  useSSL=false:就是通过账号密码进行连接-->
    <property name="url" value="jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=true"/>
    <property name="username" value="root"/>
    <property name="password" value="root"/>
</dataSource>

image-20220725102747202

报错日志:

"D:\Program Files\Java\jdk1.8.0_261\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\Program Files\IntelliJ IDEA 2020.2.1\lib\idea_rt.jar=14117:D:\Program Files\IntelliJ IDEA 2020.2.1\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\IntelliJ IDEA 2020.2.1\lib\idea_rt.jar;D:\Program Files\IntelliJ IDEA 2020.2.1\plugins\junit\lib\junit5-rt.jar;D:\Program Files\IntelliJ IDEA 2020.2.1\plugins\junit\lib\junit-rt.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\deploy.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\access-bridge-64.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\cldrdata.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\dnsns.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\jaccess.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\jfxrt.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\localedata.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\nashorn.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\sunec.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\sunjce_provider.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\sunmscapi.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\sunpkcs11.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\zipfs.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\javaws.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\jce.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\jfxswt.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\management-agent.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\plugin.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_261\jre\lib\rt.jar;D:\IdeaProjects\MyBatis-Study\mybatis-01\target\test-classes;D:\IdeaProjects\MyBatis-Study\mybatis-01\target\classes;D:\Program Files\mavenRepository\mysql\mysql-connector-java\8.0.16\mysql-connector-java-8.0.16.jar;D:\Program Files\mavenRepository\com\google\protobuf\protobuf-java\3.6.1\protobuf-java-3.6.1.jar;D:\Program Files\mavenRepository\org\mybatis\mybatis\3.4.2\mybatis-3.4.2.jar;D:\Program Files\mavenRepository\junit\junit\4.11\junit-4.11.jar;D:\Program Files\mavenRepository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.kuang.dao.UserDaoTest,test
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: 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/kuang/dao/UserMapper.xml
### The error may involve com.kuang.dao.UserDao.getUserList
### The error occurred while executing a query
### Cause: 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.
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
	at com.sun.proxy.$Proxy2.getUserList(Unknown Source)
	at com.kuang.dao.UserDaoTest.test(UserDaoTest.java:43)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: 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.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:208)
	at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:201)
	at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196)
	at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93)
	at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:385)
	at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89)
	at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138)
	at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60)
	at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
	at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
	... 28 more
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)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
	at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
	at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2243)
	at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2267)
	at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319)
	at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:966)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
	... 48 more
Process finished with exit code -1

到此这篇关于java报错Cause: java.sql.SQLException问题解决的文章就介绍到这了,更多相关java Cause: java.sql.SQLException内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  •  Spring 中 Bean 的生命周期详解

     Spring 中 Bean 的生命周期详解

    这篇文章主要介绍了Spring中Bean的生命周期详解,Java中的公共类称之为Bean或Java Bean,而Spring中的Bean指的是将对象的生命周期
    2022-09-09
  • spring boot使用thymeleaf为模板的基本步骤介绍

    spring boot使用thymeleaf为模板的基本步骤介绍

    Spring Boot项目的默认模板引擎是Thymeleaf,这没什么好说的,个人觉得也非常好,下面这篇文章主要给大家介绍了关于spring boot使用thymeleaf为模板的相关资料,需要的朋友可以参考借鉴,下面来一起学习学习吧。
    2018-01-01
  • 如何用idea数据库编写快递e站

    如何用idea数据库编写快递e站

    这篇文章主要介绍了如何用idea数据库编写快递e站,本文通过图文实例相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-01-01
  • 关于springboot加载yml配置文件的no字段自动转义问题

    关于springboot加载yml配置文件的no字段自动转义问题

    这篇文章主要介绍了关于springboot加载yml配置文件的no字段自动转义问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-02-02
  • Java正则替换手机号代码实例

    Java正则替换手机号代码实例

    本文的主要内容是Java语言中正则表达式替换手机号的第4到第7位,实现方法十分简单,同时涉及了一些正则表达式的相关用法,需要的朋友可以参考下。
    2017-09-09
  • SpringCloud学习笔记之Feign远程调用

    SpringCloud学习笔记之Feign远程调用

    Feign是一个声明式的http客户端。其作用就是帮助我们优雅的实现http请求的发送。本文将具体为大家介绍一下Feign的远程调用,感兴趣的可以了解一下
    2021-12-12
  • java 静态工厂代替多参构造器的适用情况与优劣

    java 静态工厂代替多参构造器的适用情况与优劣

    这篇文章主要介绍了java 静态工厂代替多参构造器的优劣,帮助大家更好的理解和使用静态工厂方法,感兴趣的朋友可以了解下
    2020-12-12
  • Java下载文件的4种方式总结

    Java下载文件的4种方式总结

    这篇文章主要给大家总结介绍了关于Java下载文件的4种方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-01-01
  • SpringBoot集成整合JWT与Shiro流程详解

    SpringBoot集成整合JWT与Shiro流程详解

    安全管理是软件系统必不可少的的功能。根据经典的“墨菲定律”——凡是可能,总会发生。如果系统存在安全隐患,最终必然会出现问题,这篇文章主要介绍了SpringBoot集成JWT、Shiro框架的使用
    2022-12-12
  • SSH框架网上商城项目第22战之银行图标以及支付页面显示

    SSH框架网上商城项目第22战之银行图标以及支付页面显示

    这篇文章主要为大家详细介绍了SSH框架网上商城项目第22战之银行图标以及支付页面显示,感兴趣的小伙伴们可以参考一下
    2016-06-06

最新评论