需要放在<Context></Context>之间server.xml
然后是web.xml
测试jsp
<ResourceParams name="jdbc/oracle">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@127.0.0.1:1521:ora9</value>
</parameter>
<parameter>
<name>username</name>
<value>laoyao</value>
</parameter>
<parameter>
<name>password</name>
<value>8888</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>50</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
然后是web.xml
<resource-ref>
<description>Oracle Connectiong Pool</description>
<res-ref-name>jdbc/oracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
测试jsp
<%@page contentType="text/html;charset=gb2312"%>
<%@page language="java" import="java.sql.*,
java.text.DecimalFormat,
java.text.NumberFormat"%>
<%@page import="java.util.*"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.*"%>
<%
Statement stmt = null;
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/oracle");
Connection conn = ds.getConnection();
stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from tab");
while (rs.next())
{
out.println(rs.getString("tname"));
}
%>