This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JDBC and the fly likes JNDI Driver not found with Derby database connection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "JNDI Driver not found with Derby database connection" Watch "JNDI Driver not found with Derby database connection" New topic
Author

JNDI Driver not found with Derby database connection

John Storta Jr.
Greenhorn

Joined: Jul 26, 2009
Posts: 29
I have a web app which uses a Derby database. The connection to the database establishes fine while using DriverManager.getConnection(), but if I try to establish the connection using JNDI, I get an error that the driver cannot be found.

context.xml


web.xml


Database Access Code


Error Message
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.apache.derby.jdbc.ClientDriver'


The obvious expected cause is that the DerbyClient.jar file is not in the classpath. But that is not the case here. The jar file is exactly where it should be and this can be verified by switching to the DriverManager method.

What am I missing?

Thanks
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

When you use the DriverManager, the web application loads the Driver and creates the Connection so therefore the Driver jar should be placed in the <CONTEXT>/WEB-INF/lib directory.
When you use JNDI, the connection gets managed and created by the container, so the Driver jar needs to be visible to the container in the container lib directory (not sure what you're using)
John Storta Jr.
Greenhorn

Joined: Jul 26, 2009
Posts: 29
Ahhhhhhh. It makes perfect sense now. Definitely one of those that seems obvious after the fact.

Thank you for getting me back on track.

John S.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

No charge!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: JNDI Driver not found with Derby database connection
 
Similar Threads
JNDI in entry in context.xml and web.xml
JNDI Confusion
error: Cannot load JDBC driver class
DSN name not found error with TOMCAT5.5.7
Re Connection pooling