jQuery in Action, 2nd edition*
The moose likes Tomcat and the fly likes Connection pooling in tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Connection pooling in tomcat" Watch "Connection pooling in tomcat" New topic
Author

Connection pooling in tomcat

jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
why is this below code need to be put in to web.xml while creating a datasource using tomcat5.5.
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


I used the following code and its working even without the above code in my web.xml

This is my getConnection()
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
Connection conn = ds.getConnection();
....

In my Servre.xml
<Resource name="jdbc/myoracle" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbcracle:thin:@127.0.0.1:1521:mysid"
username="scott" password="tiger" maxActive="20" maxIdle="10"
maxWait="-1"/>

Can any one tell me why is that <resource-ref> needed in the web.xml whn its working even without that code?

TOMCAT5.5 CREATING DATASOURCE
thanks,
prem
jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
do anyone have an answer for this?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Connection pooling in tomcat
 
Similar Threads
javax.servlet.ServletException: Name java: is not bound in this Context
Error confguring multiple contexts/data sources in Tomcat 5
Query in : JNDI look up of DataSource
Is this true: JNDI equals Connection Pooling
JNDI in webapps