Hi,
We are using eclipse with tomcat to deploy our web application that uses
oracle data source. Following steps were performed to get connection
pool:
1) Changes in server.xml of tomcat , added these lines
in application context
<Resource name="jdbc/JOBS_DataSource" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/JOBS_DataSource">
<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:thin:@150.235.31.48:1521:EHRS</value>
</parameter>
<parameter>
<name>username</name>
<value>jasadm</value>
</parameter>
<parameter>
<name>password</name>
<value>jasadm</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>
2) Changes in web.xml of application, added these
lines
<resource-ref>
<description>JOBS Datasource</description>
<res-ref-name>jdbc/JOBS_DataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3) Used two different approaches in code to access the
datasource
First -
java.util.Hashtable props = new java.util.Hashtable();
props.put(javax.naming.InitialContext.INITIAL_CONTEXT_FACTORY,
"org.apache.commons.dbcp.BasicDataSourceFactory");
javax.naming.InitialContext context = new
javax.naming.InitialContext(props);
Object dataSourceObject = context.lookup("jdbc/JOBS_DataSource");
myDataSource =
(DataSource)javax.rmi.PortableRemoteObject.narrow(dataSourceObject,
DataSource.class);
//third line throws naming exception - Cannot instantiate class:
org.apache.commons.dbcp.BasicDataSourceFactory
Second-
javax.naming.InitialContext initContext = new
InitialContext();
Context envContext =
(Context)initContext.lookup("java:/comp/env");
Object dataSourceObject =
envContext.lookup("jdbc/JOBS_DataSource");
//last line throws errors -> Source not found for
NamingContext.lookup(String) line: 197
//Source not found for BasicDataSource.getConnection(String, String)
line: 532
Have placed the required commons-dbcp.jar ,commons-pool.jar ,
commons-collection.jar, classes12.jar in <tomcat-install-dir>\common\lib
folder.
Any help in this regard will be highly appreciated.
Thanks & Regards,
Sandeep Tandon
JOBS - CSPD
C-09 / X-6165