java報(bào)錯(cuò)Cause: java.sql.SQLException問(wèn)題解決
問(wèn)題描述:
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:服務(wù)器時(shí)區(qū)值’ й??’無(wú)法識(shí)別或代表多個(gè)時(shí)區(qū)。 如果希望利用時(shí)區(qū)支持,則必須(通過(guò)serverTimezone配置屬性)配置服務(wù)器或JDBC驅(qū)動(dòng)程序,以使用更特定的時(shí)區(qū)值。
報(bào)錯(cuò)原因:
這是jdbc連接url路徑里面沒(méi)有加時(shí)區(qū);
解決辦法:
mybatis.config.xml文件中url加入:
serverTimezone=Asia/Shanghai
<!--dataSource數(shù)據(jù)源--> <dataSource type="POOLED"> <property name="driver" value="com.mysql.cj.jdbc.Driver"/> <!--useSSL=true:就是一般通過(guò)證書(shū)或者令牌進(jìn)行安全驗(yàn)證 useSSL=false:就是通過(guò)賬號(hào)密碼進(jìn)行連接--> <property name="url" value="jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=true"/> <property name="username" value="root"/> <property name="password" value="root"/> </dataSource>
報(bào)錯(cuò)日志:
"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
到此這篇關(guān)于java報(bào)錯(cuò)Cause: java.sql.SQLException問(wèn)題解決的文章就介紹到這了,更多相關(guān)java Cause: java.sql.SQLException內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Java中java.sql.SQLException異常的正確解決方法(親測(cè)有效!)
- java.sql.SQLException問(wèn)題解決以及注意事項(xiàng)
- 解決java.sql.SQLException:?validateConnection?false問(wèn)題的方法匯總(最全)
- 解決IDEA錯(cuò)誤 Cause: java.sql.SQLException: The server time zone value的問(wèn)題
- MySQL存儲(chǔ)表情時(shí)報(bào)錯(cuò):java.sql.SQLException: Incorrect string value:‘\xF0\x9F\x92\xA9\x0D\x0A...’的解決方法
- java.sql.SQLRecoverableException關(guān)閉的連接異常問(wèn)題及解決辦法
相關(guān)文章
spring框架集成flyway項(xiàng)目的詳細(xì)過(guò)程
今天通過(guò)本文給大家分享spring框架集成flyway項(xiàng)目的詳細(xì)過(guò)程,由于大多數(shù)都是springboot集成flyway,很少見(jiàn)到spring框架的項(xiàng)目,今天就抽空給大家介紹下spring框架集成flyway項(xiàng)目的方法,一起看看吧2021-07-07如何基于SpringWeb?MultipartFile實(shí)現(xiàn)文件上傳、下載功能
在做項(xiàng)目時(shí),后端經(jīng)常采用上傳文件組件MultipartFile,下面這篇文章主要給大家介紹了關(guān)于如何基于SpringWeb?MultipartFile實(shí)現(xiàn)文件上傳、下載功能的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-07-07Java stringBuilder的使用方法及實(shí)例解析
這篇文章主要介紹了Java stringBuilder的使用方法及實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09Mybatis-plus獲取雪花算法生成的ID并返回生成ID
本文主要介紹了Mybatis-plus獲取雪花算法生成的ID并返回生成ID,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-09-09Mybatis 傳參與排序模糊查詢(xún)功能實(shí)現(xiàn)
這篇文章主要介紹了Mybatis 傳參與排序模糊查詢(xún)功能實(shí)現(xiàn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2025-04-04SpringBoot整合logback日志的詳細(xì)步驟
這篇文章主要介紹了SpringBoot整合logback日志的詳細(xì)步驟,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-05-05JAVA讀取HDFS的文件數(shù)據(jù)出現(xiàn)亂碼的解決方案
這篇文章主要介紹了JAVA讀取HDFS的文件數(shù)據(jù)出現(xiàn)亂碼的解決方案,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下2020-11-11