tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Munroe" <brian.e.mun...@gmail.com>
Subject Re: Please help...
Date Sun, 02 Sep 2007 05:17:15 GMT
On 8/31/07, Mike Cronin <mike.cronin@fax.com> wrote:

> I am having a problem setting up a connection-pool via JNDI on Tomcat 6.0.14
> utilizing Oracle 10g. Currently I have a <Resource> for my DataSource
> referenced within a <Context> element within the server.xml file. The
> classes12.jar file which contains the Oracle Driver, exists within the
> $CATLINA-HOME/lib. I am able to successfully access my tables outside of the
> connection pool so I know that I am getting to the driver.

Mike:

First thing I can tell you, quoting directly from the Tomcat Docs:

"For Tomcat 6, unlike Tomcat 4.x, it is NOT recommended to place
<Context> elements directly in the server.xml file. This is because it
makes modifing the Context configuration more invasive since the main
conf/server.xml file cannot be reloaded without restarting Tomcat."

Now that I've said that, I'll admit I struggled with connection
pooling about a month ago.  My problem was that I was trying to place
the driver jar file in either shared/lib or WEB-INF/lib.  This was
incorrect and it needed to be in $CATALINA_HOME/common/lib, where
Tomcat could manage it.  If you read the classloader section on
tomcat.apache.org it will make sense why this is.

You mention that it is located it $CATALINA_HOME/lib [sic] - which
I'll assume is a typo, but it leads to ambiguity - did you mean
common/lib or shared/lib?  Definitely move it to common/lib.

After trying to get my JDBC resources to work in
<GlobalNamingResource> without much luck.  I ended up placing my
<Resource> definitions in META-INF/context.xml.  I don't know if you
are trying to define a global pool for all your applications or can
live with a local app configuration, I made due with a local
configuration.

Regardless, here is my "hello, world" recipe:

In META-INF/context.xml file:

<Resource name="jdbc/XEDB"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:ghg/ghg@//192.168.1.14:1521/XE"
maxActive="100"
maxIdle="30"
maxWait="10000"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
/>

I didn't mess around with setting username and password attributes, I
just provided them within the connection URL.

Finally, in a JSP, I have the following code:

(mind you this is just a 'hello, world' - I'd never actually recommend
this in real life)

<jsp:directive.page import="javax.naming.*" />
<jsp:directive.page import="java.sql.*" />
<jsp:directive.page import="javax.sql.*" />

<%

InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/XEDB");
Connection conn = ds.getConnection();

Statement s = conn.createStatement();

ResultSet rs = s.executeQuery("select * from hello");

while(rs.next()) {
    out.println(rs.getString(1) + "<br/>");
}

s.close();
conn.close();

%>

I deleted, for example, <resource-ref>'s, and basically returned
conf/server.xml and WEB-INF/web.xml back to stock, which I had mucked
up from trying things googling had suggested I try.

Hopefully this works for you too!

BTW, classes12.jar is designed for JDK 1.2 and 1.3.  From what you
mentioned, it is working just fine with your non-pooling code, but you
can download [1] a newer version (odbc14.jar comes with Oracle XE).

-- brian

[1] - http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_10201.html

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message