f



Error trying to set up JNDIand Oracle database

Hi,

I am trying to set up a very simple application accessing to my Oracle
database using Tomcat in order to let him deal with connection
pooling.

So I tried to do what what explained in the documents I found but it
seems that I have done something wrong.

I have added the following code in the server.xml (the tomcat one in
the conf directory)

<Context path="/BaseDeDonnees" reloadable="true"
docBase="C:\Dev\eclipse\workspace\BaseDeDonnees"
workDir="C:\Dev\eclipse\workspace\BaseDeDonnees\work" >
	<Logger className="org.apache.catalina.logger.SystemOutLogger"
verbosity="4" timestamp="true"/>
	<!-- Test pour faire gerer les connexions Oracle par Tomcat -->
	<Resource name="jdbc/BaseDeDonnees" scope="Shareable"
type="javax.sql.DataSource"/>
	<ResourceParams name="jdbc/BaseDeDonnees">
		<parameter>
			<name>factory</name>
			<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
		</parameter>
		<parameter>
			<name>maxWait</name>
			<value>5000</value>
		</parameter>
		<parameter>
			<name>maxIdle</name>
			<value>10</value>
		</parameter>
		<parameter>
			<name>driverClassName</name>
			<value>oracle.jdbc.driver.OracleDriver</value>
		</parameter>
		<parameter>
			<name>url</name>
			<value>jdbc:oracle:thin:@toto:1521:symp</value>
		</parameter>
		<parameter>
			<name>username</name>
			<value>myuser</value>
		</parameter>
		<parameter>
			<name>password</name>
			<value>mypassword</value>
		</parameter>
		<parameter>
			<name>validationQuery</name>
			<value>select 1</value>
		</parameter>
		<parameter>
			<name>testOnBorrow</name>
			<value>true</value>
		</parameter>
		<parameter>
			<name>removeAbandoned</name>
			<value>true</value>
		</parameter>
		<parameter>
			<name>removeAbandonedTimeout</name>
			<value>120</value>
		</parameter>
	</ResourceParams>
</Context>

then I created a web.xml for my application (so in the WEF-INF
directory of my application) that looks like this:
<!DOCTYPE web-app 
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
	<resource-ref>
 	       <description>Oracle Datasource</description>
 	       <res-ref-name>jdbc/BaseDeDonnees</res-ref-name>
 	       <res-type>javax.sql.DataSource</res-type>
 	       <res-auth>Container</res-auth>
	</resource-ref>


</web-app>

and finally I created a very simple servlet that only does this:
System.out.println("post");
		
HttpSession session = request.getSession();
		
try {
	Context initContext = new InitialContext();
	Context envContext = (Context)initContext.lookup("java:/comp/env");
	DataSource ds = (DataSource) envContext.lookup("jdbc/BaseDeDonnees");
			
	Connection conn = ds.getConnection();
			
	session.setAttribute("message","ok");
	response.sendRedirect("../reponse.jsp");	
}
catch (NamingException e) {
	session.setAttribute("message","pb naming exception");
	response.sendRedirect("../reponse.jsp");
	e.printStackTrace();
} 
catch (SQLException e) {
	session.setAttribute("message","pb sql exception");
	response.sendRedirect("../reponse.jsp");
	e.printStackTrace();
}

It seems to work fine until I try to get a connection: I have the
following error:
java.lang.NoClassDefFoundError:
org/apache/commons/collections/CursorableLinkedList
	org.apache.commons.pool.impl.GenericObjectPool.(GenericObjectPool.java:392)
	org.apache.commons.pool.impl.GenericObjectPool.(GenericObjectPool.java:266)
	org.apache.commons.dbcp.AbandonedObjectPool.(AbandonedObjectPool.java:96)
	org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:762)
	org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518)
	fr.tomcat.IdentificationServlet.doPost(IdentificationServlet.java:36)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:466)
	org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:216)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)



If anyone can help or tell me where I can find other documents (except
the Tomcat site I have already visited)

Thanks a lot for your help

Lydie
0
lsoler (1)
11/25/2004 4:26:33 PM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

0 Replies
379 Views

Similar Articles

[PageSpeed] 27

Reply: