spring链接mysql数据库问题?

[color=darkred][/color]不说了 贴代码:
测试类:
package com.hanhl.test;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.hanhl.dao.MssqlDao;
import com.hanhl.dao.MysqlDao;

public class Testcon {
public static void main(String[] args) {
final FileSystemXmlApplicationContext context=new FileSystemXmlApplicationContext ("context\database.xml");
MysqlDao mysqlDao=(MysqlDao)context.getBean("mysqldao");
List entityTypes=new ArrayList();
entityTypes=mysqlDao.getEntity();
System.out.println("+++++++++++++++++++++"+entityTypes.size()+"++++++++++++++++++++++++");
}

}
接口类:
package com.hanhl.dao;

import java.util.List;

public interface MysqlDao {
public List getEntity();
}
实现类:
package com.hanhl.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;

import com.hanhl.dao.MysqlDao;

public class MysqlDaoImpl extends NamedParameterJdbcDaoSupport implements MysqlDao {

@Override
public List getEntity() {
    // TODO Auto-generated method stub
    System.out.println("mysql");
    String getEntitySql="select * from t_entitytype";
    List entitys=new ArrayList();
    entitys=getJdbcTemplate().queryForList(getEntitySql);
    return entitys;
}

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














报异常:
[color=darkred][b]Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:382)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:458)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:466)
at org.springframework.jdbc.core.JdbcTemplate.queryForList(JdbcTemplate.java:497)
at com.hanhl.dao.impl.MysqlDaoImpl.getEntity(MysqlDaoImpl.java:18)
at com.hanhl.test.Testcon.main(Testcon.java:24)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
... 6 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1130)
... 9 more[/b][/color]
问题:是配置缺少什么吗?
[b]问题补充:[/b]
我也怀疑过啊, 所以我重新下载了dbcp1.2.2 pool1.3的包 还是不行啊!
[b]问题补充:[/b]
spring.jar
commons-pool-1.3.jar
commons-dbcp-1.2.2.jar

3个回答

[quote] Cannot load JDBC driver class 'com.mysql.jdbc.Driver' [/quote]

你的mysql驱动缺少. 不是dhcp

又是驱动问题.

检查jar包以及对应的路径是否正确.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问