当前位置: 代码迷 >> Java Web开发 >> 关于连接池的
  详细解决方案

关于连接池的

热度:145   发布时间:2010-05-06 09:05:46.0
关于连接池的
org.apache.jasper.JasperException: An exception occurred processing JSP page /chpt16/exa16_8.jsp at line 11

8: response.setContentType("text/html;charset=gbk");
9: Context initCtx = new InitialContext(); //这里四句是连接池的关键语句
10: Context envCtx = (Context) initCtx.lookup("java:comp/env");
11: DataSource ds = (DataSource)envCtx.lookup("jdbc/studadmin");
12: Connection conn = ds.getConnection();
13: String studentId=request.getParameter("studentId").trim();
14: String studentName=new String(request.getParameter("studentName").trim().getBytes("iso-8859-1"));
我试了好几个JSP网页,总是在11: DataSource ds = (DataSource)envCtx.lookup("jdbc/studadmin");上出错
下面是配置文件我的conf目录下的chpt16.xml和web-inf目录下的web.xml。
程序代码:
<Context path="/chpt16" docBase="E:\Tomcat 6.0\webapps\Webexa\chpt16" reloadable="true">
<Resource name="jdbc/studadmin" auth="Container" type="javax.sql.DataSource" username="sa" password="sadb" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" maxIdleTime="8000" maxIdle="2" minPoolSize="100"  maxPoolSize="300" maxWait="5000" maxActive="44" acquireIncrement="5" auth="Container" url="jdbc:sqlserver://localhost:1433;DatabaseName=studadmin"/>
</Context><?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
    version="2.4">
    <resource-ref>
    <description>postgreSQL Datasource example</description>
    <res-ref-name>jdbc/studadmin</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
     <welcome-file-list>
        <welcome-file>exa16_1.jsp</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

我用的是sql sever 2005还有tomcat6.0,大家帮我看下哪步有问题导致连接池连接失败的

----------------解决方案--------------------------------------------------------
太黏了,从新发下连接池数据源配置文件的代码
//chpt16.xml
<Context path="/chpt16" docBase="E:\Tomcat 6.0\webapps\Webexa\chpt16" reloadable="true">
<Resource name="jdbc/studadmin" auth="Container" type="javax.sql.DataSource" username="sa" password="sadb" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" maxIdleTime="8000" maxIdle="2" minPoolSize="100"  maxPoolSize="300" maxWait="5000" maxActive="44" acquireIncrement="5" auth="Container" url="jdbc:sqlserver://localhost:1433;DatabaseName=studadmin"/>
</Context>
//web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
    version="2.4">
    <resource-ref>
    <description>postgreSQL Datasource example</description>
    <res-ref-name>jdbc/studadmin</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
     <welcome-file-list>
        <welcome-file>exa16_1.jsp</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

----------------解决方案--------------------------------------------------------
谁帮我解决下呢?
----------------解决方案--------------------------------------------------------
  相关解决方案