datasource lookup with jndi
843854Jul 30 2002 — edited Aug 4 2002Hello,
I want to declare my database as a datasource in Tomcat4's server.xml, to use Tomcat4's connection pooling service. I've made the necessary changes in server.xml and my app's web.xml, and I'm using this code to do the lookup:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/myDb");
return ds.getConnection();
I'm getting this exception at line 3:
java.lang.ClassCastException: tyrex.jdbc.xa.EnabledDataSource
Apparently EnabledDataSource cannot be cast to DataSource ??? I also tried this code:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ConnectionPoolDataSource pds = (ConnectionPoolDataSource)envCtx.lookup("jdbc/myDb");
PooledConnection ds = pds.getPooledConnection();
return ds.getConnection();
I would REALLY appreciate any help or suggestions!