为了账号安全,请及时绑定邮箱和手机立即绑定

请教ssm框架不能获取JDBC连接的问题Could not get JDBC Connection

请教ssm框架不能获取JDBC连接的问题Could not get JDBC Connection

迷失代码林 2017-08-26 11:55:08
使用的是JDK1.7+tomcat7开发的ssm项目,地址栏输入login和register可以正确进入登录和注册页面不报错。在注册页面正确输入完用户名后由ajax提交到UserController进行验证://注册验证 @RequestMapping(value="/checkRegister",method=RequestMethod.POST)     public void checkRegister(HttpServletRequest request, HttpServletResponse response,Users user,Model model){ try {         System.out.println("已进入到注册检测模块!");         String cardId = request.getParameter("cardId");         cardId=usersService.getUserByCardId(cardId).getCardId();         PrintWriter out;         out = response.getWriter();         out.write(JSONArray.fromObject(cardId).toString());     } catch (IOException e) {                 e.printStackTrace();                     } }不过控制台并没有输出“已进入注册检测模块!”这句话,而是直接报以下错误!### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${driverClass}'### The error may exist in dao/UsersMapper.xml### The error may involve dao.UsersMapper.getUserByCardId### 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 load JDBC driver class '${driverClass}'] with root causejava.lang.ClassNotFoundException: ${driverClass}然后配置文件是在源文件夹中,源码是:driverClass=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/mysql user=root password=As3014DBCP数据源配置如下:<!-- JNDI获取数据源(使用dbcp连接池) --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="singleton"> <property name="driverClassName" value="${driverClass}" /> <property name="url" value="${url}" /> <property name="username" value="${user}" /> <property name="password" value="${password}" /> </bean>UserMapper类的代码为:public interface UsersMapper{ @MapKey("id") public Map<Integer,Users> usersList(); public Users getUserByCardId(String cardId); public Users getUserByName(String name); public Integer insertUsers(Users user); public Integer deleteUsers(Users user); public Integer updateUsers(Users user); }UserMapper.xml代码为:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"     "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="dao.UsersMapper"> <!-- 查询用户--> <select id="usersList" resultType="users" parameterType="users"> select * from users </select> <select id="getUserByName" resultType="users" parameterType="users"> select * from Users where name=#{name} </select> <select id="getUserByCardId" resultType="users" parameterType="users"> select * from Users where cardId=#{cardId} </select> <select id="insertUsers" parameterType="users"> insert into Users(cardId,name,gender,createTime,password,status) values( #{cardId},#{name},#{gender},#{createTime},#{password},#{status} ) </select> <select id="updateUsers" parameterType="users"> update users set name=#{name},gender=#{gender},createTime=#{createTime},password=#{password},status=#{status}  where cardId=#{cardId} </select> <select id="deleteUsers" parameterType="users"> delete from users where cardId=#{cardId} </select> </mapper>数据库驱动包为:mysql-connector-java-5.1.7-bin.jar之前项目中还有5.1.0和5.1.26版本的mysql驱动,与现状错误是一样的。driverClass这个类没问题的,在jar包可以找得到。我找来找去也发现不了是哪的问题,请求各位大神帮忙指点!!!
查看完整描述

1 回答

?
执着小哥

TA贡献1条经验 获得超1个赞

driverClass=com.mysql.jdbc.Driver改为driver=com.mysql.jdbc.Driver

<property name="driverClassName" value="${driverClass}" />改为<property name="driverClassName" value="${driver}" />

查看完整回答
1 反对 回复 2017-09-04
  • 1 回答
  • 0 关注
  • 20320 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信