• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

A question about creating a Connection pool that uses Oracle JDBC

Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I have an issue with creating a connection pool within a web application in order to be used by several servlets. I appreciate if you could kindly give me a hand.

I'm using:

Web server: Apache-tomcat: 6.0.18
Oracle Database 11g Enterprise: - Production
Operating system: Linux (ubuntu 8.10)
IDE: Sun Netbeans
Oralce JDBC Drivers: (ojdbc6.jar and orai18n.jar)
JDK 1.6

Usually, just for creating a connection to my database (without using a connection pool), I proceed in the following way:

This works pretty well allowing to communicate with my oracle database. By this method I have run several projects
with different queries (SELECT, INSERT, UPDATE, DELETE ,etc.) and each time it worked without any problem and
returned the result of the query. Therefore I think that there is no problem with JDBC drivers

However, when I want to create a connection pool, it seems that the lookup method cannot locate Oracle JDBC drivers. That is,

Just after calling dataSource.getConnection() the java.lang.NullPointerException is thrown.

Any idea?

Thanks in advance,

And for your information, here are context.xml and web.xml files for my project
Here is my context.xml

my web.xml

dariyoosh za
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

I looked again in different forums, and it seems that there are many
who have encountered my problem. I found a solution in Sun forums in the
following thread


The user named 0_kevin_0 suggests that the Ressource element be defined
directly inside the server.xml file of the Tomcat server, rather than in
context.xml of the web application (this was the method for older versions of Tomcat).

I proceeded according to his method, but at the same time I modified a little my servlet
I added three System.out.println inside the servlet in order to better see where exactly the problem is

my servlet:

After running, I saw that the first two messages were printed, that is,
Ok, the environment java/env exists
Ok, the dataSource was created successfully

And right after connection = dataSource.getConnection(); I have the
following error message in the Netbeans Tomcat tab:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class ' ' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1150)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at servlets.Servlet1.doPost(Servlet1.java:51)
at servlets.Servlet1.doGet(Servlet1.java:26)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
at java.sql.DriverManager.getDriver(DriverManager.java:253)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143)
... 17 more

I'm going to show you the complete content of my server.xml file, inside the
<GlobalNamingResources> </GlobalNamingResources> I have added the
Ressource definition for Oracle (it is between the following lines:

<!-- ********** Oracle 11g Ressource definition (begin) ************ -->
<!-- ********** Oracle 11g Ressource definition (End) ************ -->

And then in Netbeans, my context.xml for my application is

And my web.xml file for my web application

What do you think? Where did I make a mistake (or maybe several mistakes?!)

Thank you very much for your attention,

Kind Regards,
dariyoosh za
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I solved the problem.

Finally I uninstalled Tomcat 6.0.18 and instead of that I installed the previous version, that is, Tomcat 5.5.
It works pretty well !!

I didn't do any modification to the server.xml, I just defined resource elements in the
application context and I put the reference in web.xml. I didn't even need to add oracle driver to WEB-INF library, I
just put it in $CATALINA_HOME/common/lib

For those who have the same problem, the following information about the content and format of context.xml and web.xml
files maybe helpful.

Context.xml (this is my application context.xml file and not the server context.xml)

and the web.xml file

My servlet in which I did the test

dariyoosh za
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

Finally I managed to run my application also with Tomcat 6.0.18. There was only two lines that had to be modified
in the context.xml file (the context of my application project and not server's)

Instead of writing

we had to write:

- No modification was needed to be done at server level (niether server.xml nor server context.xml)
- I just added the ojdbc6.jar in $CATALINA_HOME/lib (I didn't even need to add it in WEB-INF/lib of my project)
- The servlet used to do the test was the same that I presented in my precedent post.

For those who have encountered my problem and are interested in the format of the web.xml and context.xml
with Tomcat 6.0, you can find them below:

Oracle server: Oracle 11g Enterprise
Tomcat server version: 6.0.18
Oracle driver: ojdbc.jar
IDE: Netbeans 6.5.1

The context.xml file of the web application

The web.xml of my web application

Ok, now I'm happy as the original problem is completely solved

Posts: 2658
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great. You resolved this all by yourself.
I was lurking this thread, but didn't know the solution to your problem. Thanks for posting it, and for informing us on your approach to troubleshoot this.
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for sharing this. I am stuck with this problem for last 2 days. Hope it will work for me.
Posts: 70327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch and it is good to see that old threads can still be useful.
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic