Get OracleDataSource with JNDI

From: Vasileios Lourdas <Vasileios.Lourdas_at_eurodyn.com>
Date: Mon, 24 Mar 2003 12:51:50 +0200
Message-ID: <3E7EE346.846FF1DE_at_eurodyn.com>


Hello,

I 've been using Tomcat 4.1.24 on Windows with Oracle JDBC thin driver from 9i R2 to connect to a 8.1.6 database on a Linux server. I have created a datasource for the specific context (/test) from the Tomcat administration pages using oracle.jdbc.pool.OracleDataSource as the JDBC driver class. The whole idea is to retrieve an OracleDataSource object for use inside some jsps. The code snippet for this is:
***

Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:/comp/env");

OracleDataSource ds =
(OracleDataSource)envContext.lookup("jdbc/myOracle"); Connection dbConn = ds.getConnection();
***

The name for the datasource is jdbc/myOracle. The problem with the above code is that i get a java.lang.ClassCastException when invoking the page from the browser. The lookup method of course returns an Object object but i can't see why this object cannot cast to OracleDataSource.

If anyone has managed to do what i want to do, please enlighten me. This has puzzled me for some time now...

Regards,
Vasilis Received on Mon Mar 24 2003 - 11:51:50 CET

Original text of this message