Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using c3p0 connection Pooling in a tomcat Spring based App

I have a Spring Based Web App running under tomcat 6. Now, I want to use c3p0 connection pooling instead of tomcat's default DBCP. So, from the c3p0 help doc, I have defined the data source in context.xml something like:

<Resource name="jdbc/sample" auth="Container"
     driverClassName="oracle.jdbc.driver.OracleDriver"
     url="jdbc:oracle:thin:@someServer:1551:xyz"
     username="userName"
     password="pwd"
     validationQuery="SELECT 1 FROM dual"
     testOnBorrow="true"
     testWhileIdle="true"
     factory="org.apache.naming.factory.BeanFactory" 
     type="com.mchange.v2.c3p0.ComboPooledDataSource" 
     maxPoolSize="20" 
     minPoolSize="5" 
     acquireIncrement="1" 
   />

Now, the documentation says, I should Include the following in web.xml:

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

I also have the following in applicationContext.xml:

<jee:jndi-lookup id="sampleDataSource" resource-ref="true"
    jndi-name="jdbc/sample" />

When I start the tomcat, I get

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

Without c3p0 and using default connection pooling in tomcat6 works fine.

Any help would be appreciated.

like image 592
Nehal Damania Avatar asked Mar 09 '11 14:03

Nehal Damania


1 Answers

this thread is old, so the answer is for future use - i had the same issue (this is how i got to this thread).

i solved the problem after performing a small research. there are some definitions, that the used data source doesn't support. when you remove those definitions and rename others, the data source is created with no problem and without a need to the resourceLink mentioned above.

in the following link you can find the list of supported definitions. http://www.mchange.com/projects/c3p0/#tomcat-specific

the following link is to the data source's java doc. according to the methods that are listed there, you can configure the resource tag in the context.xml file. http://www.mchange.com/projects/c3p0/apidocs/com/mchange/v2/c3p0/ComboPooledDataSource.html

like image 137
javaist Avatar answered Nov 01 '22 19:11

javaist