org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection
来源:互联网 发布:sql最后一行加合计行 编辑:程序博客网 时间:2024/05/17 07:28
最近在复习ssm时,做了一个小demo。在这其中就遇到许多问题,而出现这些问题时,让自己最大的一个感受就是多翻阅官方文档。虽然现在市场有许多书籍和视频,这些资源用归用。但是当你跟着这些教程走下去,最会有一些问题的。自己也有从中查看出来。
例如:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
The error may exist in file [C:\seckill\target\classes\mapper\SeckillDao.xml]
The error may involve org.seckill.dao.SeckillDao.queryById
The error occurred while executing a query
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:76)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399)at com.sun.proxy.$Proxy13.selectOne(Unknown Source)at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:165)at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:69)at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)at com.sun.proxy.$Proxy14.queryById(Unknown Source)at org.seckill.dao.SeckillDaoTest.queryById(SeckillDaoTest.java:32)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.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)at org.junit.runners.ParentRunner.run(ParentRunner.java:309)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)at org.junit.runner.JUnitCore.run(JUnitCore.java:160)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
然而出现这些原因就是:
错误的jdbc.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/seckill?useUnicode=true&characterEncoding=utf-8
username=root
password=root
spring-dao.xml 配置如下
<!-- 基本属性 url、user、password --> <property name="jdbcUrl" value="${url}" /> <property name="user" value="${username}" /> <property name="password" value="${password}" /> <!--c3p0私有属性--> <property name="maxPoolSize" value="30"/> <property name="minPoolSize" value="10"/> <!--关闭连接后不自动commit--> <property name="autoCommitOnClose" value="false"/> <!--获取连接超时时间--> <property name="checkoutTimeout" value="1000"/> <!--当获取连接失败重试次数--> <property name="acquireRetryAttempts" value="2"/></bean>
然而官网提供的配置是:
<property name="driverClass" value="${jdbc.driver}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <!--c3p0连接池的私有属性--> <property name="maxPoolSize" value="30"/> <property name="minPoolSize" value="10"/> <!--关闭连接后不自动commit--> <property name="autoCommitOnClose" value="false"/> <!--获取连接超时时间--> <property name="checkoutTimeout" value="1000"/> <!--当获取连接失败重试次数--> <property name="acquireRetryAttempts" value="2"/></bean>
而正确的jdbc.properties是:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost/seckill?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
最后还是我们要多去翻看spring官方文档,毕竟权威性高!
3 0
- org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection
- org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection
- org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection解决办法
- org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection;
- org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection
- org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons
- org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exc
- Oracle数据源:org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection;
- Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nes
- Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection问题排查
- org.springframework.jdbc.CannotGetJdbcConnectionException
- Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could no
- org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for
- org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for
- Could not get JDBC Connection
- Could not get JDBC Connection
- Could not get JDBC Connection
- Could not get JDBC Connection
- Java学习笔记(八)--基本数据类型包装类 Math类 Random类 Date类
- 第4章 需求分析
- [leetCode刷题笔记]173. Binary Search Tree Iterator
- Spring中利用反射调用service方法
- 分类算法系列2----逻辑回归特征选择
- org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection
- mybatis1 笔记
- Java 实例
- MySQL中查询已定义字段的类型和长度命令
- 类模板的定义和使用
- IoT的那些操作系统
- 自创网页首页”我的书屋“
- REST--REpresentational State Transfer
- JAVA实现重建二叉树(《剑指offer》)