Jakarta ee Java中的连接池

Jakarta ee Java中的连接池,jakarta-ee,Jakarta Ee,我正在尝试用java实现连接池。我已经编写了一个java代码和一个jsp文件。当我在tomcat6.0.20上运行它时,我得到了以下错误 javax.servlet.ServletException:无法为连接URL“null”创建类的JDBC驱动程序 在这条线上 连接conn=ds.getConnection 您是否配置了数据源?请按照以下步骤操作 一,。创建ConnectionManager类: 二,。创建QueryManager类: 四,。Config context.xml使用JDBC驱

我正在尝试用java实现连接池。我已经编写了一个java代码和一个jsp文件。当我在tomcat6.0.20上运行它时,我得到了以下错误

javax.servlet.ServletException:无法为连接URL“null”创建类的JDBC驱动程序

在这条线上
连接conn=ds.getConnection

您是否配置了数据源?

请按照以下步骤操作

一,。创建ConnectionManager类:

二,。创建QueryManager类:


四,。Config context.xml使用JDBC驱动程序

是的,我已经配置了Tomcat的context.xml文件。我已经在那里编写了资源信息。我已经创建了一个web.xml,在其中引用了context.xml中的资源声明。您是在尝试实现连接池,还是只是配置它?
public class ConnectionManager {
 Vector connectionPool = new Vector(0, 1);
private static ConnectionManager obConnectionManager = new ConnectionManager();

    /**
     * TX Data Source.
     */
    DataSource obTXDataSource = null;

    /**
     * Non TX Data Source.
     */
    DataSource obNonTXDataSource = null;

    /**
     * A non tx data source created for using it in reports.
     * This has been created for using it in reports with non transactional connection.
     *
     * The existing non- transaction connection attribute and function is being called from
     * many modules. In order to have lesser impact this function and attribute is being introduced.
     * This has been done after the conference call had with Retesh - SMS
     */

    DataSource reportsNonTxDataSource = null;

    /**
     * Constuctor for the class.
     */
    private ConnectionManager() {
    }

    /**
     * Returns instance of the class.
     * @return Instance of the class
     */
    public static ConnectionManager getInstance() {
        return obConnectionManager;
    }

    /**
     * Returns the database connection using a transactional Datasource.
     * @return The database connection using a transactional Datasource
     * @exception PersistenceException
     */
    public Connection makeTXConnection()
        throws PersistenceException {
        try {
            if (obTXDataSource == null) {
                obTXDataSource = ServiceLocator.getTXDataSource();
            }
            Connection obConnection = obTXDataSource.getConnection();
            connectionPool.add(obConnection);
            return obConnection;
        } catch (ServiceLocatorException se) {
            throw new PersistenceException("PE002",
                "Error making database connection: " + se.getMessage());
        } catch (SQLException se) {
            throw new PersistenceException("PE002",
                "Error making database connection: " + (new Integer(se.getErrorCode())).toString() +
                se.getMessage());
        }
    }
}
public class QueryManager {
    /**
     * This is an object of Debug class for locating error in the process.
     */
    private Debug debug = new Debug(QueryManager.class);

    /**
     * The PreparedStatement instance.
     */
    private PreparedStatement obPreparedStatement = null;

    /**
     * The Connection instance.
     */
    private Connection obConnection = null;

    private int procedureTimeOut = 0;//V3.2

    /**
     * Constuctor for the class.
     */
    public QueryManager() {
    }

    /**
     * Executes the SELECT statement.
     * 
     * @param sql
     *            The SELECT statement
     * @param params
     *            The parameters passed to the SELECT statement
     * @return the Array of Data fetched after executing the SELECT statement
     * @exception PersistenceException
     */
    public ArrayList executeSQL(String sql, Object[] params)
            throws PersistenceException {
        java.util.Date startDate = new java.util.Date();
        java.util.Date endDate = null;
        try {
            obConnection = ConnectionManager.getInstance()
                    .makeNonTXConnection();
            obPreparedStatement = obConnection.prepareStatement(sql);
            int length = 0;
            if (params != null) {
                length = params.length + 1;
            }
            for (int i = 1; i < (length); i++) {
                if (params[i - 1] == null) {
                    obPreparedStatement.setNull(i, java.sql.Types.VARCHAR);
                } else {
                    obPreparedStatement.setObject(i, params[i - 1]);
                }
            }
            ArrayList result = getResult();
            endDate = new java.util.Date();

            return result;

        } catch (SQLException se) {
            debug.log(Debug.ERROR, "SQL Exception", se);
            se.printStackTrace();
            throw new PersistenceException("PE003", createErrString(
                    se.getErrorCode(), se.getMessage()));

        } finally {
            closeConnection(obConnection, obPreparedStatement);
            if (endDate == null) {
                endDate = new java.util.Date();
            }
            debug.log(Debug.INFO, constructLogString(startDate, endDate, sql));
            startDate = endDate = null;

        }
    }
}
ArrayList result = null;
String query = "Select * From emp where empID=?";

try {
     Object[] params={1};
     result = queryManager.executeSQL(query,params);
} catch (PersistenceException e) {

}
return result;