请帮一下, tomcat 5.0.25 配置连接池时总是报错,不能取得连接,以下是配置文件,测试文件和错误信息.
TOMCAT_HOME\conf\Catalina\localhost\testdb.xml 如下:
<?xml version='1.0' encoding='utf-8'?>
<Context crossContext="true" displayName="testdb" docBase="testdb" path="/testdb" reloadable="true">
<Resource name="testdb" type="javax.sql.DataSource"/>
<ResourceParams name="testdb">
<parameter>
<name>url</name>
<value>jdbc:informix-sqli://162.162.162.162:8888/mydb:INFORMIXSERVER=test</value>
</parameter>
<parameter>
<name>password</name>
<value>test</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.informix.jdbc.IfxDriver</value>
</parameter>
<parameter>
<name>username</name>
<value>test</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
</ResourceParams>
</Context>
TOMCAT\webapps\testdb\index.jsp 如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%
Connection conn = null;
Context initCtx = new InitialContext();
if (initCtx == null)
throw new Exception("不能获取Context!");
Context ctx = (Context) initCtx.lookup("java:comp/env");
//获取连接池对象
Object obj = (Object) ctx.lookup("testdb");
if (obj == null)
throw new Exception("不能取得连接池对象");
//类型转换
javax.sql.DataSource ds = (javax.sql.DataSource) obj;
conn = ds.getConnection();
Statement stmt = conn.createStatement();
String strSql = "select * from t_operatordef;";
ResultSet rs = stmt.executeQuery(strSql);
while(rs.next()){
out.println(rs.getString(1));
}
rs.close();
stmt.close();
conn.close();
out.println("连接池测试成功");
%>
错误信息如下:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Cannot get a connection, pool exhausted, cause: Could not create a validated object
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.index_jsp._jspService(index_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
root cause
org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted, cause: Could not create a validated object
org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:148)
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518)
org.apache.jsp.index_jsp._jspService(index_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)