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

目录
  • spring myBatis数据库连接异常
    • 报错如下
  • 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的“}”

如下:

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进行核对

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • Mybatis-Spring连接mysql 8.0配置步骤出错的解决方法

    本文为大家解决了Mybatis-Spring 连接 MySQL8.0 的配置步骤出错问题,供大家参考,具体内容如下 环境以及配置文件 JDBC jar版本 : 8.0.11 Mybatis jar版本 : 3.4.6 Spring jar版本 : 4.3.18 Mybatis-Spring jar版本 : 1.3.1 配置信息文件 : db.properties Spring配置文件 : applicationContext.xml 测试路径如下图 配置db.properties 配置db.pr

  • SpringBoot2.0整合tk.mybatis异常解决

    pom配置如下(标准简易版): <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> </parent> <properties> <java.version>1.8&

  • springboot mybatis调用多个数据源引发的错误问题

    目录 springboot mybatis调用多个数据源错误 报错 解决方法 springboot-mybatis多数据源及踩坑 springboot项目结构如下 springboot配置文件内容如下 动态数据源的配置类如下 最关键的来了 springboot mybatis调用多个数据源错误 报错 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init meth

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

    目录 spring myBatis数据库连接异常 报错如下 myBatis连接数据库时报错原因归纳 报错信息 spring myBatis数据库连接异常 报错如下 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  Cause: org.springframewo

  • spring+mybatis 通过@ResponseBody返回结果中文乱码的解决方法

    问题发生: 通过@Responsebody返回 @ResponseBody @RequestMapping(value ="/selectByFormId",method = RequestMethod.GET) public Map<String,Object> getClassName(String formId){ List<String> list =formInfoService.selectClassName(formId); Map<Stri

  • Spring+Mybatis+Mysql搭建分布式数据库访问框架的方法

    一.前言 用Java开发企业应用软件, 经常会采用Spring+MyBatis+Mysql搭建数据库框架.如果数据量很大,一个MYSQL库存储数据访问效率很低,往往会采用分库存储管理的方式.本文讲述如何通过Spring+Mybatis构建多数据库访问的架构,并采用多线程提升数据库的访问效率. 需要说明一下,这种方式只适合数据库数量.名称固定,且不是特别多的情况.针对数据库数量不固定的情况,后面再写一篇处理方案. 二.整体方案 三.开发环境准备 3.1 下载Spring.Mybatis.Mysql

  • Spring+Mybatis动态切换数据源的方法

    功能需求是公司要做一个大的运营平台: 1.运营平台有自身的数据库,维护用户.角色.菜单.部分以及权限等基本功能. 2.运营平台还需要提供其他不同服务(服务A,服务B)的后台运营,服务A.服务B的数据库是独立的. 所以,运营平台至少要连三个库:运营库,A库,B库,并且希望达到针对每个功能请求能够自动切换到对应的数据源(我最终实现是针对Service的方法级别进行切换的,也可以实现针对每个DAO层的方法进行切换.我们系统的功能是相互之间比较独立的). 第一步:配置多数据源 1.定义数据源: 我采用的

  • MySQL数据库连接异常汇总(值得收藏)

    在Centos上部署项目发现一个奇怪的问题,数据库连接一直抛异常.于是花了两个小时搜了各种数据库连接异常导致的原因,最终问题得以解决.同时,把解决过程中搜集到的异常信息汇总一下,当大家遇到类似的问题时,给大家以思路.必须珍藏. 问题现象 先来说说我遇到的问题.项目中遇到的问题很奇怪,在Centos上安装了Mysql数据库,项目使用的是Spring Boot. 项目在本地启动连接服务器数据库正常.本地数据库客户端连接服务器数据库正常.服务器本地连接client连接数据库正常.唯独把项目部署到服务器

  • Spring+MyBatis实现数据库读写分离方案

    推荐第四种 方案1 通过MyBatis配置文件创建读写分离两个DataSource,每个SqlSessionFactoryBean对象的mapperLocations属性制定两个读写数据源的配置文件.将所有读的操作配置在读文件中,所有写的操作配置在写文件中. 优点:实现简单 缺点:维护麻烦,需要对原有的xml文件进行重新修改,不支持多读,不易扩展 实现方式 <bean id="abstractDataSource" abstract="true" class=

  • Spring boot 数据库连接断线重连问题

    问题描述 我正在做的这个项目,数据库是跨区并且不由自己管理的.防火墙会每隔一段时间就自动断开数据库连接. 于是需要对application.properties的datasource进行配置.Ps:我使用是mybatis连接数据库. 配置及具体含义 #初始化连接 spring.datasource.initial-size=10 #最大空闲连接 spring.datasource.max-idle=20 #最小空闲连接 spring.datasource.min-idle=5 #最大连接数量 s

  • Spring集成Swagger常见错误及解决办法

    概览 在当下几乎所有的公司都采用了前后端分离的开发模式,Swagger作为了在API在线文档工具,几乎是后端开发的必备组件,最近公司的有个项目,在项目启动和打开Swagger页面时候,后端产生了大量的异常日志,虽然不影响现在的正常启动,不过,每次看到大量的异常日志,对于有代码洁癖的我,不能忍.于是乎今天抽了个时间把以下这些问题解决了,解决后再看日志,简直不能再爽歪歪啦~ 下面对问题以及解决的办法做个记录. 问题一 异常描述:No enum constant org.springframework

  • spring boot 不连接数据库启动的解决

    目录 spring boot 不连接数据库启动 原因在于 解决方法 SpringBoot项目取消数据库配置 1. 错误 2. 原因 3. 如何不配 spring boot 不连接数据库启动 用spring boot 搭建的项目,在配置文件不连接数据库启动项目会报错. 原因在于 spring boot默认会加载 org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration 类,DataSourceAutoConfig

  • mybatis空值插入处理的解决方法

    适用于入参类型为对象的 刚学习完mybatis如何插入空值,现在来总结一下 上面是我的项目,打开测试类,插入空值试一下 上面是我的Mapper文件.实体类和测试类,方法传的是对象类型的,25行是设置姓名的,现在不设置姓名执行一下实体类 控制台报错,不能为映射设置参数,无效的列类型 解决方法:在mapper文件调用的方法设置idbcType,由于我的sName是String类型的,处理空值设置 jdbcType=VARCHAR,这里要注意不同类型设置的jdbaType是不一样的,参考下图 设置结束

随机推荐