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.
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.
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.
Joined: Jul 26, 2009
Ahhhhhhh. It makes perfect sense now. Definitely one of those that seems obvious after the fact.