tomcat版本5.0.28,oracle版本9.2server.xml配置 <ResourceParams name="jdbc/test"> <parameter> <name>maxActive</name> <value>20</value> </parameter> <parameter> <name>maxWait</name> <value>-1</value> </parameter> <parameter> <name>password</name> <value>tiger</value> </parameter> <parameter> <name>url</name> <value>jdbc:oracle:thin:@192.168.123.16:1521:shan</value> </parameter> <parameter> <name>driverClassName</name> <value>oracle.jdbc.driver.OracleDriver</value> </parameter> <parameter> <name>maxIdle</name> <value>10</value> </parameter> <parameter> <name>username</name> <value>scott</value> </parameter> </ResourceParams>index.jsp内容<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ page import="java.sql.*"%><%@ page import="javax.naming.*"%><%@ page import="javax.sql.*"%><!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN"><html> <head> </head> <body> <% Context initContext = new InitialContext(); Context envContext = (Context) initContext.lookup("java:/comp/test"); DataSource db = (DataSource) envContext.lookup("jdbc/test"); //javablogorl为<Resource>元素中name属性的值 Connection conn = db.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM emp"); while (rs.next()) { out.print(rs.getString("empno") + " "); out.print(rs.getString("ename") + "<br>"); } rs.close(); stmt.close(); conn.close(); %> </bady></html>执行index.jsp时页面会报出javax.servlet.ServletException: Name test is not bound in this Context这个错误,不知道哪里设置有问题,请高手指导!
DataSource db = (DataSource) new InitialContext().lookup("java:/comp/jdbc/test"); Connection conn = db.getConnection(); 如果没记错的话连接池应该这样写吧你那错误提示意思就是那个连接池的名字没找到好像是你写错了