org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection
这个问题困扰许久,许久。原来只是data source的properties引入文件,el表达式前必须加jdbc
原文解决参考:http://blog.csdn.net/liwuyang2013/article/details/25986597
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:)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:)
at com.zhexiang.mybatis_springmvc.dao.impl.CustomerDaoImpl.selectCustomerByID(CustomerDaoImpl.java:)
at com.zhexiang.mybatis_springmvc.dao.impl.CustomerDaoImplTest.testSelectCustomerByID(CustomerDaoImplTest.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at junit.framework.TestCase.runTest(TestCase.java:)
at junit.framework.TestCase.runBare(TestCase.java:)
at junit.framework.TestResult$.protect(TestResult.java:)
at junit.framework.TestResult.runProtected(TestResult.java:)
at junit.framework.TestResult.run(TestResult.java:)
at junit.framework.TestCase.run(TestCase.java:)
at junit.framework.TestSuite.runTest(TestSuite.java:)
at junit.framework.TestSuite.run(TestSuite.java:)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:)
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:)
at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:)
at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:)
at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:)
... 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:)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:)
... more
Caused by: java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:)
at java.lang.reflect.Constructor.newInstance(Constructor.java:)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:)
... more
出现以上错误原因是:数据源的错误配置:
错误的jdbc.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=gbk
username=root
password=root
错误的spring配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- config db property file location -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties"/>
</bean> <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
</beans>
正确的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>
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 可能出现的原因 ...
- jdbc连接oracle时报错 Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableC
错误: Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; ...
- Spring 整合Mybatis 出现了Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create Poola
我出现的 报错信息如下: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionExc ...
- org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exc ...
- [数据库] - org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection
MySQL的驱动改名了,如果使用原来的com.mysql.jdbc.Driver 那么会提醒驱动不正常了,那么新的MySQL驱动名为:com.mysql.cj.jdbc.Driver 之后还报错,如题 ...
- ### 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 chec
数据库连接超时,是数据库连接时的相关配置写错,例如:数据库密码,驱动等问题
- 搭建SSM项目时报错(org.springframework.jdbc.CannotGetJdbcConnectionException)
严重: Servlet.service() for servlet [SpringMVC] in context with path [/ssm] threw exception [Request p ...
- springCloud微服务调用失败【CannotGetJdbcConnectionException: Failed to obtain JDBC Connection】
详情如下: 2019-07-28 10:56:18.229 ERROR 16212 --- [nio-8081-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet ...
- mySql版本的相关问题:com.mysql.cj.jdbc.Driver和com.mysql.jdbc.Driver
Mysql版本的相关问题:com.mysql.cj.jdbc.Driver和com.mysql.jdbc.Driver 1. 在使用mysql时,控制台日志报错如下: Loading class `c ...
随机推荐
- POJ 3376 Finding Palindromes(manacher求前后缀回文串+trie)
题目链接:http://poj.org/problem?id=3376 题目大意:给你n个字符串,这n个字符串可以两两组合形成n*n个字符串,求这些字符串中有几个是回文串. 解题思路:思路参考了这里: ...
- TypeScript 2 : 获取当前日期及前后范围日期【Array】
前言 今天有个接口字段需求,要写一个今天及前几天的日期传过去: 在网上找了下都木有什么比较好的方案:就自己写了一个. 因为技术栈就是NG2+TS2+WEBPACK,这里的代码需要一定的TS2及ES6的 ...
- **CodeIgniter-cURL扩展
Work with cURL easily from your CodeIgniter application. Tweet Contributor : philsturgeon Email : Lo ...
- pomelo 安装
1. 安装nodejs ,python ,C++运行环境(VS2012以上版本) 2.npm install -g node-gyp --registry=https://registry.npm.t ...
- hdoj2546 饭卡(DP,01背包)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2546 思路 首先要判断卡里的钱是不是大于等于5元,如果不足5元,直接输出余额:如果大于等于5元,则先留 ...
- Jersey入门三:创建一个JavaEE的Web项目
1.在终端中输入如下命令,创建一个名为的simple-service-webapp项目: mvn archetype:generate -DarchetypeArtifactId=jersey-qui ...
- elementUI 学习入门之 Select 选择器
Select 选择器 基础用法 <el-select v-model="val1" placeholder="请输入"> <el-option ...
- 不定期更新的IDEA功能整理
目录 不定期更新的IDEA功能整理 idea 命令 Preferences 和 Project Structure Keymap HTTP Proxy Postfix Completion 插件 插件 ...
- 超实用 Git 使用方式介绍
都说程序员若是不知道 GitHub 就不是一个合格的程序员,其实这话说的过分了,不知道就学嘛,今天我们就来说说 Git 和 GitHub 到底是什么. 我们在开发软件的时候,常常是需要多人协作完成,这 ...
- TCP 建立连接为什么要握 3 次手?
上次已经说过,没有协议,不成方圆,计算机之间的通信更是依赖于协议.今天就重点分析一下 TCP 协议. 传输控制协议 TCP 是一种面向连接的.可靠的.基于字节流的传输层通信协议,由IETF的RFC 7 ...