c3p0使用配置文件方式连接不上数据库,手动设置可以

用c3p0连接池用配置文件出现连接不上的情况,手动模式可以连接上数据库?

public void demo2() {

        Connection connection = null;

        PreparedStatement statement = null;

        ResultSet resultSet = null;

        try {

             ComboPooledDataSource dataSource=new ComboPooledDataSource();

  ;
             connection= dataSource.getConnection();




            String sql = "select * from account";

            statement = connection.prepareStatement(sql);

            //设置参数

            //执行sql
            resultSet = statement.executeQuery();

            while (resultSet.next()) {

                System.out.println(resultSet.getInt("id") + resultSet.getString("username") + resultSet.getDouble("memony"));

            }

        } catch (Exception e) {

            e.printStackTrace();
        } finally {
            JDBCUtils.release(resultSet, connection, statement);

        }

    }

 

这是配置文件的写法

<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>  
    <!-- This is default config! -->  
    <default-config>  
        <property name="driverClass">com.mysql.jdbc.Driver</property>
        <property name="jdbcUrl">jdbc:mysql://localhost:3306/contacts?characterEncoding=utf8</property>
        <property name="user">root</property>
        <property name="password">123456</property>
        
        <property name="acquireIncrement">5</property>
        <property name="initialPoolSize">10</property>
        <property name="minPoolSize">5</property>
        <property name="maxPoolSize">20</property> 

        <property name="maxStatements">0</property>
        <property name="maxStatementsPerConnection">5</property> 
    </default-config>  
  
    <!-- This is my config for mysql-->  
    <named-config name="mysql">  
        <property name="driverClass">com.mysql.jdbc.Driver</property>  
        <property name="jdbcUrl">jdbc:mysql://localhost:3306/test</property>  
        <property name="user">root</property>  
        <property name="password">123456</property>  
        <property name="initialPoolSize">10</property>  
        <property name="maxIdleTime">30</property>  
        <property name="maxPoolSize">100</property>  
        <property name="minPoolSize">10</property>  
        <property name="maxStatements">200</property>  
    </named-config>
</c3p0-config>