users@glassfish.java.net

Oracle connection in application

From: justinas <cofeinesunshine_at_gmail.com>
Date: Fri, 08 Oct 2010 19:45:56 +0300

hello

my web-application uses specifig OracleJDBC driver features, so it need
oracle.jdbc.pool.OracleDataSource retured from JNDI into my app, so I
can get oracle.odbc.OracleConnection from it.

My code:

   public static OracleConnection getJNDIConnection() {
         OracleConnection conn = null;
         try {
             InitialContext context = new InitialContext();
// DataSource dataSource = (DataSource)
context.lookup("jdbc/datasrc");
             OracleDataSource dataSource = (OracleDataSource)
context.lookup("jdbc/datasrc");
             conn = (OracleConnection) dataSource.getConnection();

             //TODO sutvarkyti loginima
         } catch (NamingException ex) {
             log.error("klaida gaunant DB connection'a is JNDI", ex);
         } catch (SQLException ex) {
             log.error("klaida gaunant DB connection'a is JNDI", ex);
         }
         return conn;
     }


I'm using Glassfish 3.0.1

configured it using admin panel, created connection pool Resource Type:
javax.sql.ConnectionPoolDataSouce, Datasource
Classname:oracle.jdbc.pool.OracleDataSource.


When executing code i get error:

java.lang.ClassCastException: com.sun.gjc.spi.jdbc40.DataSource40 cannot
be cast to oracle.jdbc.pool.OracleDataSource



How in app i can have OracleConnection one or another way using
glassfish connection pooling?