建议按以下步骤,如果还有问题,要将详细的异常贴出来。
配置tomcat下的conf下的context.xml文件,在之间添加连接池配置:
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:mydb"
username="bmgis"
password="bmgis"
maxActive="100"
maxIdle="30"
maxWait="10000" />
2.配置你的应用下的web.xml中的之间加入:
DB Connection
jdbc/mydb
javax.sql.DataSource
Container
在以往的tomcat当中还需要在web.xml指定相应的resource,在tomcat 5.5以后的版本不写也可以,但建议还是配置。
3.把连接数据库的第三方驱动放到${CATALINA_HOME}/lib下面就ok了
4.测试程序test.jsp如下:
<%@ page import="javax.naming.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
Connection conn = ds.getConnection();
conn.close();
%>
Connection refused: 表示无法建立TCP连接,检查IP和端口是否正确。
org.apache.jasper.JasperException: An exception occurred processing JSP page /a.jsp at line 21
看多一点错误的描述