users@glassfish.java.net

Re: Oracle connection in application

From: justinas <cofeinesunshine_at_gmail.com>
Date: Tue, 12 Oct 2010 08:59:02 +0300

thank you all,

just for the record, I found another way to get connection:

InitialContext context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup("jdbc/datasrc");
OracleDataSource ods = dataSource.unwrap(OracleDataSource.class);
conn = (OracleConnection) ods.getConnection();

On 2010.10.12 06:24, Jagadish Prasath Ramu wrote:
> To get physical connections, you can refer :
> http://docs.sun.com/app/docs/doc/820-7695/beamt?l=en&a=view
>
> Thanks,
> -Jagadish
>
> On Fri, 2010-10-08 at 19:45 +0300, justinas wrote:
>
>> 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?
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>