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.
Web server: Apache-tomcat: 6.0.18
Oracle Database 11g Enterprise: 126.96.36.199.0 - Production
Operating system: Linux (ubuntu 8.10)
IDE: Sun Netbeans
Oralce JDBC Drivers: 188.8.131.52.0-Production (ojdbc6.jar and orai18n.jar)
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.
Thanks in advance,
And for your information, here are context.xml and web.xml files for my project
Here is my context.xml
Joined: Apr 12, 2009
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
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
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)
Caused by: java.lang.NullPointerException at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
... 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:
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,
Joined: Apr 12, 2009
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)
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: