Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get DBCP Connection Pooling to work with H2 database

Status
Not open for further replies.

cpjust

Programmer
Sep 23, 2003
2,132
US
Hi,
I've got a servlet on Tomcat on Solaris and I'm using the H2 database (
It currently works without using DBCP, but to improve performance, I need to use connection pooling. I tried following the instructions I found here: But it's throwing a NoInitialContextException during the call to lookup().
Here's my getConnection() function:
Code:
private Connection getConnection() throws QueueException
{
	try
	{
		Context initContext	= new InitialContext();
		DataSource ds = (DataSource)initContext.lookup( "java:comp/env/QueueDB" );
		return ds.getConnection();
	}
	catch ( NamingException e )
	{
		throw new QueueException( e );
	}
	catch ( SQLException e )
	{
		throw new QueueException( e );
	}
}

Does anyone know what's wrong? I've never used DBCP and barely know anything about Tomcat configuration.
 
Which configuration are you referring to? The Tomcat configuration (context.xml and/or web.xml) or the getConnection() code?
I tried using the code from that link first and couldn't get it to work either, so I went looking on other sites for specific H2 examples...
 
OK, I think I was debugging the wrong thing. Now it's getting the InitialContext, but I'm getting a new exception on the return statement:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.h2.Driver'

Code:
	Context initContext	= new InitialContext();
	Context envContext	= (Context)initContext.lookup( "java:comp/env" );
	DataSource ds = (DataSource)envContext.lookup( "jdbc/h2" );
	return ds.getConnection();
 
OK, I got it fixed.
Apparently I had to put h2.jar in $CATALINA_HOME/lib instead of in my servlet's WEB-INF/lib directory.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top