tomcat JDNI DB connection pool to Oracle
843854Jun 18 2002 — edited Oct 14 2007I've been successfully making JDBC connections directly in my JSP
Class.forName("oracle.jdbc.driver.OracleDriver");
ora_conn = DriverManager.getConnection("jdbc:oracle:oci8:@oracle8", "user", "password");
Not I try to setup my Tomcat 4.0.2's JDNI DB connection pool, but I can't get it to work
Here is what I've done so far
1. Move the Oracle Drivers (classes12.zip) into <TOMCAT_HOME>\lib and
<TOMCAT_HOME>\common\lib directories and rename them to classes12.jar
2. Added the following codes to my webapp's web.xml
<resource-ref>
<res-ref-name>jdbc/ora</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3. Added the following codes within the <Context> </Context> tag of <TOMCAT_HOME>\conf\server.xml
<Resource name="jdbc/ora" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/ora">
<parameter>
<name>user</name>
<value>system</value>
</parameter>
<parameter>
<name>password</name>
<value>manager</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbc:oracle:oci8:@oracle8</value>
</parameter>
</ResourceParams>
4. try to make connection within my JSP
<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.naming.*" %>
<%
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/ora");
Connection conn1 = ds.getConnection();
out.println("Win2000 Oracle Connected!<br>");
}
catch (SQLException E) {
out.println("<br>unable to get connection on ora !");
out.println("<br>SQLException: " + E.getMessage());
out.println("<br>SQLState: " + E.getSQLState());
out.println("<br>VendorError: " + E.getErrorCode());
}
%>
Results :
unable to get connection on ora !
SQLException: Cannot load JDBC driver class 'null'
SQLState: null
VendorError: 0
Why? I'm able to make connection call JDBC directly in my other JSP, but not when I try to get the connection via JDNI Context ...??
Thank you in advnace
ku