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.
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.
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
posted
0
Ahhhhhhh. It makes perfect sense now. Definitely one of those that seems obvious after the fact.