ssm测试mybatis时出现无法连接数据库驱动的错误

2023-05-16

org.apache.ibatis.exceptions.PersistenceException:   
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root '@'localhost' (using password: YES))  
### The error may exist in mapper/CustomerMapper.xml  
### The error may involve com.zhexiang.mybatis_springmvc.model.selectCustomerByID  
### The error occurred while executing a query  
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root '@'localhost' (using password: YES))  
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)  
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)  
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)  
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)  
    at com.zhexiang.mybatis_springmvc.dao.impl.CustomerDaoImpl.selectCustomerByID(CustomerDaoImpl.java:18)  
    at com.zhexiang.mybatis_springmvc.dao.impl.CustomerDaoImplTest.testSelectCustomerByID(CustomerDaoImplTest.java:37)  
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
    at java.lang.reflect.Method.invoke(Method.java:597)  
    at junit.framework.TestCase.runTest(TestCase.java:176)  
    at junit.framework.TestCase.runBare(TestCase.java:141)  
    at junit.framework.TestResult$1.protect(TestResult.java:122)  
    at junit.framework.TestResult.runProtected(TestResult.java:142)  
    at junit.framework.TestResult.run(TestResult.java:125)  
    at junit.framework.TestCase.run(TestCase.java:129)  
    at junit.framework.TestSuite.runTest(TestSuite.java:255)  
    at junit.framework.TestSuite.run(TestSuite.java:250)  
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)  
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)  
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)  
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)  
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)  
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)  
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)  
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root '@'localhost' (using password: YES))  
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)  
    at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:81)  
    at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)  
    at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:279)  
    at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:72)  
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59)  
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)  
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)  
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)  
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)  
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)  
    ... 23 more  
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root '@'localhost' (using password: YES))  
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)  
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)  
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)  
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)  
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)  
    ... 33 more  
Caused by: java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES)  
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)  
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)  
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)  
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:925)  
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1704)  
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1250)  
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2465)  
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)  
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)  
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)  
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)  
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)  
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)  
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)  
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)  
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)  
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)  
    at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)  
    at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)  
    at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)  
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)  
    ... 37 more  

出现以上错误原因是:数据源的错误配置:

错误的jdbc.properties

driver=com.mysql.jdbc.Driver  
url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=gbk  
username=root  
password=root
``

错误的spring配置文件:


正确的jdbc.properties配置:

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=gbk
jdbc.username=root
jdbc.password=root

Spring4.0.4 官方文档数据源配置:

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xsi:schemaLocation="  
        http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
        http://www.springframework.org/schema/context  
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">  

    <!-- Scans within the base package of the application for @Components to configure as beans -->  
    <context:component-scan base-package="org.springframework.docs.test" />  

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">  
        <property name="driverClassName" value="${jdbc.driverClassName}"/>  
        <property name="url" value="${jdbc.url}"/>  
        <property name="username" value="${jdbc.username}"/>  
        <property name="password" value="${jdbc.password}"/>  
    </bean>  

    <context:property-placeholder location="jdbc.properties"/>  

</beans>  

原文来自:http://blog.csdn.net/liwuyang2013/article/details/25986597?utm_source=tuicool&utm_medium=referral

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ssm测试mybatis时出现无法连接数据库驱动的错误 的相关文章

随机推荐

  • UE4设置 只修改蓝图节点的语言为英文

    原因 因为在查找需要的节点时 xff0c 输入英文更符合命名法 xff0c 为了更好的查找节点 xff0c 把节点的名字改成英文当然更好 xff01 操作步骤 取消下面的勾选即可 结果
  • Unity的InputSystem使用实践

    如何使用 首先得有一个PlayerInput在场景中 xff0c 每一个PlayerInput表示一个玩家 在Actions里面选择自己的Actions xff0c 可以新建 xff1a 比如在PlayerMaps中的MoveActions
  • 虚幻4C++编程入门(搬运1)

    首先我们将使用虚幻编辑器中的类向导生成基础 C 43 43 类 xff0c 以便蓝图稍后进行延展 下图展示了向导的第一步 新建一个 Actor 这里根据对character pawn和actor的描述 xff0c 知道了pawn是actor
  • 虚幻4C++编程入门深入了解

    这部分我们将讨论基础构建块以及它们之间相互关联的方式 在此我们将了解虚幻引擎如何使用 继承和合成构建自定义游戏性功能 游戏性类 xff1a 对象 Actor 和组件 多数游戏性类派生自 4 个主要类型 它们是 UObject AActor
  • 窗口焦点丢失问题分析

    从slog中的systemlog可以看出如下信息 xff1a 01 01 08 29 03 732 633 936 I WindowManager Relayout invis Window 42244420 u0 Keyguard mEx
  • ubuntu不能挂载U盘问题

    插上U盘一个弹窗显示不能挂载系统 就不附图了 自己也是在到处找了问题 xff0c 试了很多教程 xff0c 要么看不懂要么没用要么瞎写的 最后实测一个有用的 因为ubuntu默认不能识别U盘 解决方法 xff1a 安装exfat磁盘格式工具
  • unity3d个人版怎么改变主题=>黑色

    是有很多文章都有介绍如何使用操作 xff0c 我就不再多说 xff0c 主要是那个软件的问题 xff08 在下面我会附上winhex的下载地址和详细教程 xff09 一般会出问题的地方是试用版会出很多问题 xff0c 比如什么200k以上不
  • 【正则表达式】基础应用(匹配matches(regex))(转)

    正则表达式基础应用 匹配 字符 x 字符 x 反斜线字符 字符类 abc a b 或 c xff08 简单类 xff09 abc 任何字符 xff0c 除了 a b 或 c xff08 否定 xff09 a zA Z a 到 z 或 A 到
  • 一种动态更新flink任务配置的方法

    文章目录 1 原理2 例 xff0c 整数过滤2 1 并行度为12 2 并行度大于12 3 完整代码 参考链接 1 原理 参考Flink Spark 如何实现动态更新作业配置 xff0c 讲得比较详细 xff0c 这篇的文章的参考参考文献也
  • 一种Hudi on Flink动态同步元数据变化的方法

    文章目录 一 背景二 官方Schema Evolution例子三 Flink 43 Hudi实现Schema Evolution四 96 HoodieFlinkStreamer 96 流程浅析及扩展方法4 1 FlinkKafkaConsu
  • 一种处理Hive元数据与文件类型不同时SQL查询失败的方法

    文章目录 一 背景二 分析过程2 1 环境及测试数据2 1 1 环境2 1 2 测试数据 2 2 select语句异常分析2 2 1 异常分析2 2 2 捕获异常位置 2 3 insert overwrite语句异常分析2 3 1 异常分析
  • 一种处理Hive元数据与文件类型不同时SQL查询失败的方法(二)

    文章目录 一 异常触发SQL二 异常处理三 Hive on Spark依赖的Hive jar包部署 继上一篇之后 xff0c 又发现了一种新的报错位置 本篇对这种情况进行处理 xff0c 并验证这种处理方式是否适用于Hive on Spar
  • Hive分区表修改(增删)列

    文章目录 一 环境及测试数据二 删除列2 1 测试表test22 2 DDL删除列 xff1f 2 3 代码连接Hive Metastore删除列2 3 1 同时更新表与分区元数据 三 添加列结论参考链接 一 环境及测试数据 环境 xff1
  • python通过kerberos连接impala操作hive

    一 python2版本 1 docker基础镜像 tobyhferguson impyla tester 2 安装相关包及配置 2 1 安装包 参考python3 6 5基于kerberos认证的hive和hdfs连接调用 yum span
  • 美化Windows中的CMD/PowerShell,以及替代方案

    命令行字体美化 微软对命令会话窗口中的字体元数据有着一些苛刻的要求 xff0c 使得大部分好看的字体不能应用于CMD PowerShell xff0c 传统的有衬线字体不仅不美观还不易分清1和l 网上有各种针对一些字体改动注册表的做法 xf
  • 【获奖公布】“我的2016”主题征文活动

    还记得2015的年末 xff0c 2016的新年伊始 xff0c 你给自己定下的目标 xff0c 对自己许下的诺言么 xff1f 时光荏苒 xff0c 一年又在指缝间溜走了 xff0c 离2016的结束还剩十多天 xff0c 在接下来的这十
  • 程序员成长路线

    回顾过去 xff0c 我们会清晰地看见走过来的路线 xff0c 但面向未来我们又该如何走下去 xff1f 但凡过往 xff0c 皆为序章 xff0c 过去不可变 xff0c 未来才是希望 xff0c 而如何去规划并管理好未来的成长进化之路
  • 求解最大连通子图

    使用networkx里面的函数来求解最大连通子图 coding utf 8 34 34 34 Created on Wed Mar 11 21 38 53 2020 64 author Administrator 34 34 34 impo
  • Result Maps collection already contains value for BaseResultMap

    由于mybatis简单易学 xff0c 比起Hibername来 xff0c 更容易上手 xff0c 代码也能自动生成 这几天研究了下代码自动生成的 xff0c 参考 xff1a http 0609xiaohua iteye com blo
  • ssm测试mybatis时出现无法连接数据库驱动的错误

    org apache ibatis exceptions PersistenceException Error querying database Cause org springframework jdbc CannotGetJdbcCo