You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Isabel Lameda <IL...@bancofederal.com> on 2002/09/03 14:50:05 UTC

tomcat JDNI DB connection pool to Oracle

Anabody could help me, i´ve been trying to do this for days!!!!

I've been successfully making JDBC connections directly in my JSP 

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con =
DriverManager.getConnection("jdbc:oracle:oci8:"+login+"/"+passwd+"@"+databas
e)

Now I'm trying to setup my Tomcat 4.0.9'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>\common\lib 
directory and rename it to classes12.jar

2. Added the following codes to my webapp's web.xml

<resource-ref>
<res-ref-name>jdbc/homebank</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


3. Added the following codes within the <GlobalNamingResources>
</GlobalNamingResources> tag
   of <TOMCAT_HOME>\conf\server.xml

<Resource name="jdbc/homebank" auth="Container"
              type="javax.sql.DataSource"/> 

<ResourceParams name="jdbc/homebank">
  <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:oci8@homebank</value>
  </parameter>
  <parameter>
    <name>username</name>
    <value>scott</value>
  </parameter>
  <parameter>
    <name>password</name>
    <value>tiger</value>
  </parameter>
  <parameter>
    <name>maxActive</name>
    <value>20</value>
  </parameter>
  <parameter>
    <name>maxIdle</name>
    <value>10</value>
  </parameter>
  <parameter>
    <name>maxWait</name>
    <value>-1</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/homebank");
Connection conn1 = ds.getConnection();
out.println("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 advance
 
P.S.: i´ve search the archives and found nothing that could help me.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: tomcat JDNI DB connection pool to Oracle

Posted by Vance Christiaanse <ci...@twcny.rr.com>.
Isabel,


Your ResourceParams element contains

  <parameter>
    <name>url</name>
    <value>jdbc:oracle:oci8@homebank</value>
  </parameter>

but for 4.0.x "url" should be "driverName". ("url" is a much clearer name!)

(See
http://jakarta.apache.org/tomcat/tomcat-4.0-doc/jndi-resources-howto.html)

Also, you don't need the <factory> element.

Hope this helps,

Vance

----- Original Message -----
From: "Isabel Lameda" <IL...@bancofederal.com>
To: <to...@jakarta.apache.org>
Sent: Tuesday, September 03, 2002 8:50 AM
Subject: tomcat JDNI DB connection pool to Oracle


Anabody could help me, i´ve been trying to do this for days!!!!

I've been successfully making JDBC connections directly in my JSP

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con =
DriverManager.getConnection("jdbc:oracle:oci8:"+login+"/"+passwd+"@"+databas
e)

Now I'm trying to setup my Tomcat 4.0.9'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>\common\lib
directory and rename it to classes12.jar

2. Added the following codes to my webapp's web.xml

<resource-ref>
<res-ref-name>jdbc/homebank</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


3. Added the following codes within the <GlobalNamingResources>
</GlobalNamingResources> tag
   of <TOMCAT_HOME>\conf\server.xml

<Resource name="jdbc/homebank" auth="Container"
              type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/homebank">
  <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:oci8@homebank</value>
  </parameter>
  <parameter>
    <name>username</name>
    <value>scott</value>
  </parameter>
  <parameter>
    <name>password</name>
    <value>tiger</value>
  </parameter>
  <parameter>
    <name>maxActive</name>
    <value>20</value>
  </parameter>
  <parameter>
    <name>maxIdle</name>
    <value>10</value>
  </parameter>
  <parameter>
    <name>maxWait</name>
    <value>-1</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/homebank");
Connection conn1 = ds.getConnection();
out.println("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 advance

P.S.: i´ve search the archives and found nothing that could help me.

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: tomcat JDNI DB connection pool to Oracle

Posted by Simon T <to...@sydneybluegum.com>.
I am running ok with tomcat 4.1.9  using the oracle thin driver.

Tomcat 4.1 JNDI datasource examples doc say -

Use of the OCI driver should simply involve a changing thin to oci in 
the URL string.

<name>url</name>
<value>jdbc:oracle:thin:myschema@127.0.0.1:1521:mysid</value>

Your url in server.xml is 
<value>jdbc:oracle:oci8@homebank</value>

If homebank is in your tnsname.ora maybe tomcat is having problems locating it.


Or

Do you have the commons jar files e.g. commons-dbcp.jar in  common\lib

The commons jar file were installed for me when i installed tomcat 4.1.9.

Good luck.

Simon


Isabel Lameda wrote:

>Anabody could help me, i´ve been trying to do this for days!!!!
>
>I've been successfully making JDBC connections directly in my JSP 
>
>DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
>Connection con =
>DriverManager.getConnection("jdbc:oracle:oci8:"+login+"/"+passwd+"@"+databas
>e)
>
>Now I'm trying to setup my Tomcat 4.0.9'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>\common\lib 
>directory and rename it to classes12.jar
>
>2. Added the following codes to my webapp's web.xml
>
><resource-ref>
><res-ref-name>jdbc/homebank</res-ref-name>
><res-type>javax.sql.DataSource</res-type>
><res-auth>Container</res-auth>
></resource-ref>
>
>
>3. Added the following codes within the <GlobalNamingResources>
></GlobalNamingResources> tag
>   of <TOMCAT_HOME>\conf\server.xml
>
><Resource name="jdbc/homebank" auth="Container"
>              type="javax.sql.DataSource"/> 
>
><ResourceParams name="jdbc/homebank">
>  <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:oci8@homebank</value>
>  </parameter>
>  <parameter>
>    <name>username</name>
>    <value>scott</value>
>  </parameter>
>  <parameter>
>    <name>password</name>
>    <value>tiger</value>
>  </parameter>
>  <parameter>
>    <name>maxActive</name>
>    <value>20</value>
>  </parameter>
>  <parameter>
>    <name>maxIdle</name>
>    <value>10</value>
>  </parameter>
>  <parameter>
>    <name>maxWait</name>
>    <value>-1</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/homebank");
>Connection conn1 = ds.getConnection();
>out.println("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 advance
> 
>P.S.: i´ve search the archives and found nothing that could help me.
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>  
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>