一、搭建ssm项目时插入数据出现错误

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:836)at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
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.GeneratedConstructorAccessor39.newInstance(Unknown Source)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:2120)at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2143)at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1310)at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:967)at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)... 11 moreorg.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
### The error may exist in file [E:\background\ssm-crud\target\classes\mapper\DepartmentMapper.xml]
### The error may involve com.atguigu.crud.dao.DepartmentMapper.insert
### The error occurred while executing an update
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)at com.sun.proxy.$Proxy23.insert(Unknown Source)at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)at com.sun.proxy.$Proxy24.insert(Unknown Source)at com.atguigu.crud.test.MapperTest.testCRUD(MapperTest.java:41)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:59)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)at org.junit.runners.ParentRunner.run(ParentRunner.java:413)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)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: org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
### The error may exist in file [E:\background\ssm-crud\target\classes\mapper\DepartmentMapper.xml]
### The error may involve com.atguigu.crud.dao.DepartmentMapper.insert
### The error occurred while executing an update
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)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.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)... 37 more
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82)at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68)at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85)at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)... 43 more
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158)at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116)at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)... 51 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)... 55 more

解决方案:

url加上:useJDBCCompliantTimezoneShift=true&serverTimezone=UTC

注意:

根据版本配置datasource

当connector版本小于6.0 :

jdbc.driverClass=com.mysql.jdbc.Driver

大于6.0版本:

jdbc.driverClass=com.mysql.cj.jdbc.Driver

Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not b相关推荐

  1. Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: com.mysql.cj.jdbc.Driv

    解答 这种情况常见于直接打开jsp页面时ide报错,主要原因是不同意html这个静态页面,jsp它本身的特性导致其需要在运行的服务端下才可以打开. 所以打开前需要先启动tomcat等一类服务器,在服务 ...

  2. Could not get JDBC Connection; nested exception is java.sql.SQLException:

    报错信息: Could not get JDBC Connection; nested exception is java.sql.SQLException: The server time zone ...

  3. Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsEx

    我的是再宿主机连接虚拟机的时候报的这个错 The last packet sent successfully to the server was 0 milliseconds ago. The dri ...

  4. Field ‘gmt_create‘ doesn‘t have a default value; nested exception is java.sql.SQLException: Field ‘g

    涉及技术: SpringBoot 测试出错: IDEA 添加数据时出错 org.springframework.dao.DataIntegrityViolationException: ### Err ...

  5. Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot get a connection, p

    报文: ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbc ...

  6. nested exception is java.sql.SQLException: Data truncated for column 'PassWord' at row 72

    tomcat启动没有错误,进入登录界面发现登不进去,出现错误: 2016-08-17 14:52:44 -43568 [http-8080-4] DEBUG   - ==>  Preparing ...

  7. nested exception is java.sql.SQLException: HOUR_OF_DAY: 0 -> 1

    Cause: java.sql.SQLException: HOUR_OF_DAY: 0 -> 1 HOUR_OF_DAY: 0 -> 1; nested exception is jav ...

  8. 解决bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 1. 报错: ### Cause: java.sql.SQLSyntaxErrorException ...

  9. 使用jdbc:nested exception is java.sql.SQLException: No value specified for parameter或bad SQL grammar

    bad SQL grammar:错误出现原因有下面几种: 下面这个是正确代码: 1.可能是数据库连接时,数据库名写错 2.数据库的表名写错 3.定义的sql里面的属性和values里面的属性个数不一致 ...

  10. bad SQL grammer []; nested exception is java.sql.SQLSyntaxErrorException:ORA-00918:未明确定义列

    出现这个问题主要是因为列名重复,导致不能明确定义列. 很多表及字段关联以后,往往会出现这个问题,还是要细心才能解决.

最新文章

  1. 聊一聊Spring中的线程安全性
  2. 在遗传算法中出现等式约束_排序算法中的稳定性-等式的处理
  3. 计算机专业好的广东二本学校排名2015,2015年广东省二本大学排名名单
  4. SR:嗜酸古菌的代谢和进化模式
  5. pyhton3 json.dumps 去除空格
  6. Win64 驱动内核编程-6.内核里操作注册表
  7. C# using的用法
  8. 【UML】UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)
  9. 静态分配内存和动态分配内存
  10. python计算数组元素的和_python中数组的运算
  11. mysql心得体会一百字_MYSQL CPU 100%实例详解
  12. TypeError: ‘NoneType‘ object is not callable--python报错解决办法
  13. 通过ODBC实现ACCESS与SQL数据互导(临安人才网 )
  14. Delphi 调试连接 任意Android手机/平板/盒子
  15. 基于SSM的宠物商城系统
  16. 确定你的电脑是否支持安装64位操作系统
  17. 分享个强大的抓包工具
  18. MICRO USB引脚定义以及接法
  19. 《TCP/IP详解卷一:协议》学习笔记
  20. ESP32 开发笔记(四)LVGL控件学习 ColorPicker 颜色选择器控件

热门文章

  1. 毕加索传记的艺术和历史
  2. 大数据常见专有名词解释
  3. linux 中more、less 和 most 的区别
  4. 实验一计算机网络基础知识,计算机网络实验基础知识 集线器的使用
  5. 计算机桌面文件为何不能剪贴,电脑不能复制粘贴是什么原因【方法介绍】
  6. 有什么软件可以连接到linux系统升级,linux系统和应用程序升级方法
  7. 免费mysql数据库_免费mysql空间,免费数据库,免费MYSQL云数据库申请 | 帮助信息-动天数据...
  8. Javascript的事件冒泡
  9. (单细胞-SingleCell)单细胞可变剪切流程(一)
  10. Chrome浏览器的复用