Type mismatch: cannot convert from ComboPooledDataSource to DataSource

来源:互联网 发布:java 压缩文件 编辑:程序博客网 时间:2024/06/15 19:57

在Eclipse 中使用c3p0数据库资源管理时:

private static DataSource dataSource = null;static{dataSource = new ComboPooledDataSource(“”);//""内的字符串为:自己在c3p0-config.xml中配置的name//这里会报错:Type mismatch: cannot convert from ComboPooledDataSource to DataSource//大致意思就是  new ComboPooledDataSource("") 的返回结果不是  DataSource 的对象//原因是上面导包出现了问题:import org.apache.tomcat.jdbc.pool.DataSource;(这个包不对)//正确的包 import javax.sql.DataSource;}/*** 返回数据源的一个Connection 对象* @return 返回一个connection* @throws SQLException */public static Connection getConnection() throws SQLException{return (Connection) dataSource.getConnection();}
阅读全文
0 0