服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Java教程 - Spring myBatis数据库连接异常问题及解决

Spring myBatis数据库连接异常问题及解决

2023-02-14 15:01vera_vera_vera Java教程

这篇文章主要介绍了Spring myBatis数据库连接异常问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

spring myBatis数据库连接异常

报错如下

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 [E:\Code_zxt\MVNWebDemo\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.TestQueryById(SeckillDaoTest.java:38)
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:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.exceptions.PersistenceException: 

首先去看mysql服务是否启动,发现启动正常。

再去看jdbc.properties文件里面url username等写对没有,写的是正确的,但是发现password是unused。去看spring-dao.xml(spring和mybatis相关的配置文件),发现漏写了password的“}”

如下:

Spring myBatis数据库连接异常问题及解决

myBatis连接数据库时报错原因归纳

报错信息

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:oracl


### The error may exist in sqlMapper/UsersMapper.xml
### The error may involve test.findUserById
### The error occurred while executing a query
### Cause: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:oracl

这里报错的可能性在于配置文件中的jdbc.url=jdbc:oracle:thin:@localhost:1521:oracl的oracl不是Oracle数据库的SID,数据库的SID是orcl,所以会报这个错,可以通过服务查看Oracle的SID进行核对 

以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/vera_vera_vera/article/details/78154201

延伸 · 阅读

精彩推荐
  • Java教程教你使用java实现去除各种空格

    教你使用java实现去除各种空格

    本文给大家汇总介绍了5种java中去除空格的方法,分别是String.trim()、str.replace(" ", "");、replaceAll(" +","");以及自定义的remove函数,非常的简单实用,需要的小...

    hebedich6932019-12-13
  • Java教程Spring boot实现一个简单的ioc(2)

    Spring boot实现一个简单的ioc(2)

    这篇文章主要为大家详细介绍了Spring boot实现一个简单ioc的第二篇,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    clayanddev3082020-09-21
  • Java教程关于javaWeb中405错误的解决方法

    关于javaWeb中405错误的解决方法

    下面小编就为大家带来一篇关于javaWeb中405错误的解决方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    Java教程网6102020-09-28
  • Java教程Mybatis传list参数调用oracle存储过程的解决方法

    Mybatis传list参数调用oracle存储过程的解决方法

    怎么利用MyBatis传List类型参数到数据库存储过程中实现批量插入数据?接下来通过本文给大家介绍Mybatis传list参数调用oracle存储过程,需要的朋友可以参考下...

    球球爱2932020-08-27
  • Java教程java版十大排序经典算法:完整代码(4)

    java版十大排序经典算法:完整代码(4)

    优秀的文章也不少,但是Java完整版的好像不多,我把所有的写一遍巩固下,同时也真诚的希望阅读到这篇文章的小伙伴们可以自己去从头敲一遍,不要粘贴...

    牛哄哄的柯南6872021-10-24
  • Java教程Java编写的24点纸牌游戏

    Java编写的24点纸牌游戏

    这篇文章主要介绍了Java编写的24点纸牌游戏的相关资料,需要的朋友可以参考下 ...

    hebedich2182019-12-14
  • Java教程Java String对象使用方法详解

    Java String对象使用方法详解

    这篇文章主要介绍了Java String对象使用方法详解的相关资料,需要的朋友可以参考下...

    Java教程网2762020-09-19
  • Java教程一文带你初识java中的String类

    一文带你初识java中的String类

    String代表字符串,Java 程序中的所有字符串字面值(如 "abc" )都作为此类的实例实现,这篇文章主要给大家介绍了关于java中String类的相关资料,需要的朋友可以参...

    文墨轩11902022-02-27