我用proxool做连接池的时候出现异常

错误信息
2008-1-24 11:46:04 org.logicalcobwebs.proxool.ProxoolFacade registerConnectionPool
信息: Proxool 0.9.0RC3 (10-Jan-2007 01:38)
2008-1-24 11:46:04 org.logicalcobwebs.proxool.ProxoolDriver connect
严重: Problem
org.logicalcobwebs.proxool.ProxoolException: Attempt to refer to a unregistered pool by its alias 'DBPool'
    at org.logicalcobwebs.proxool.ConnectionPoolDefinition.doChange(ConnectionPoolDefinition.java:250)
    at org.logicalcobwebs.proxool.ConnectionPoolDefinition.<init>(ConnectionPoolDefinition.java:147)
    at org.logicalcobwebs.proxool.ProxoolFacade.registerConnectionPool(ProxoolFacade.java:96)
    at org.logicalcobwebs.proxool.ProxoolDriver.connect(ProxoolDriver.java:77)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at selfservice.PoolManager.getConnection(PoolManager.java:30)
    at selfservice.PoolManager.getQuery(PoolManager.java:99)
    at selfservice.PoolManager.main(PoolManager.java:121)
java.sql.SQLException: org.logicalcobwebs.proxool.ProxoolException: Attempt to refer to a unregistered pool by its alias 'DBPool'
    at org.logicalcobwebs.proxool.ProxoolDriver.connect(ProxoolDriver.java:109)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at selfservice.PoolManager.getConnection(PoolManager.java:30)
    at selfservice.PoolManager.getQuery(PoolManager.java:99)
    at selfservice.PoolManager.main(PoolManager.java:121)



web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <servlet>
        <servlet-name>ServletConfigurator</servlet-name>
        <servlet-class>
            org.logicalcobwebs.proxool.configuration.ServletConfigurator
        </servlet-class>
        <init-param>
            <param-name>xmlFile</param-name>
            <param-value>WEB-INF/proxool.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Admin</servlet-name>
        <servlet-class>
            org.logicalcobwebs.proxool.admin.servlet.AdminServlet
        </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Admin</servlet-name>
        <url-pattern>/admin</url-pattern>
    </servlet-mapping>
</web-app>


proxool.xml
<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
    <proxool>
        <alias>DBPool</alias>
        <driver-url>
            jdbc:microsoft:sqlserver://127.0.0.1:1433;databasename=test
        </driver-url>
        <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
        <driver-properties>
            <property name="user" value="sa" />
            <property name="password" value="1" />
        </driver-properties>
        <house-keeping-sleep-time>90000</house-keeping-sleep-time>
        <maximum-new-connections>150</maximum-new-connections>
        <prototype-count>3</prototype-count>
        <maximum-connection-count>100</maximum-connection-count>
        <minimum-connection-count>3</minimum-connection-count>
    </proxool>
</something-else-entirely>


类文件
package selfservice;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.logicalcobwebs.proxool.ProxoolException;
import org.logicalcobwebs.proxool.ProxoolFacade;
import org.logicalcobwebs.proxool.admin.SnapshotIF;

public class PoolManager {

    private static int activeCount = 0;

    public PoolManager() {

    }

    /**
     * 获取连接 getConnection
     * 
     * @param name
     * @return
     */
    public Connection getConnection() {
        try {
            Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");// proxool驱动类
            Connection conn = DriverManager.getConnection("proxool.DBPool");
            // 此处的DBPool是在proxool.xml中配置的连接池别名
            showSnapshotInfo();

            return conn;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    /**
     * 此方法可以得到连接池的信息 showSnapshotInfo
     */
    private void showSnapshotInfo() {
        try {
            SnapshotIF snapshot = ProxoolFacade.getSnapshot("DBPool", true);
            int curActiveCount = snapshot.getActiveConnectionCount();// 获得活动连接数
            int availableCount = snapshot.getAvailableConnectionCount();// 获得可得到的连接数
            int maxCount = snapshot.getMaximumConnectionCount();// 获得总连接数
            if (curActiveCount != activeCount)// 当活动连接数变化时输出的信息
            {
                System.out.println("活动连接数:" + curActiveCount
                        + "(active)  可得到的连接数:" + availableCount
                        + "(available)  总连接数:" + maxCount + "(max)");
                activeCount = curActiveCount;
            }
        } catch (ProxoolException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取连接 getConnection
     * 
     * @param name
     * @return
     */
    public Connection getConnection(String name) {
        return getConnection();
    }

    /**
     * 释放连接 freeConnection
     * 
     * @param conn
     */
    public void freeConnection(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 释放连接 freeConnection
     * 
     * @param name
     * @param con
     */
    public void freeConnection(String name, Connection con) {
        freeConnection(con);
    }

    public void getQuery() {
        try {
            Connection conn = getConnection();
            if (conn != null) {
                Statement statement = conn.createStatement();
                ResultSet rs = statement
                        .executeQuery("select * from t_emp");
                int c = rs.getMetaData().getColumnCount();
                while (rs.next()) {
                    System.out.println();
                    for (int i = 1; i <= c; i++) {
                        System.out.print(rs.getObject(i));
                    }
                }
                rs.close();
            }
            freeConnection(conn);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        PoolManager manager = new PoolManager();
        manager.getQuery();
    }
}



这样写有什么问题吗?我弄不明白为什么会出错,难道是还要配置什么吗?

你可能感兴趣的:(java,sql,xml,Web,jdbc)