Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Simple JDBC via JNDI lookup on weblogic : RmiDataSource_12120_WLStub error?

colin the aardvark-OracleJun 26 2014 — edited Oct 15 2014

Hi All,

  Really basic problem here hopefully.

Environment :

    Jdeveloper 11g

    Java 1.6

    Weblogic 12.1.2

    ojdbc6.jar

    database 11.2

All I'm doing is trying to code a very simple JDBC test from Jdeveloper to weblogic.

Without using JNDI, it all works fine using the following code :

        OracleDataSource ods = new OracleDataSource();

        ods.setUser("user");

        ods.setPassword("pwd");

        ods.setDriverType("thin");

        ods.setServerName("mycomputer.uk.oracle.com");

        ods.setDatabaseName("orcl");

        ods.setPortNumber(1521);        

        Connection conn2 = ods.getConnection();

        DatabaseMetaData meta = conn2.getMetaData();

        System.out.println("JDBC is " + meta.getDriverVersion());          

        System.out.println("Obj ods was: " + ods.getClass().getName());

the final s.o.p  prints out 'OracleDataSource.'

But with this code :

        Hashtable ht2 = new Hashtable();

        ht2.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");

        ht2.put(Context.PROVIDER_URL, "t3:/mycomputer.uk.oracle.com:7001");

        Context ctx4 = null;

        ctx4 = new InitialContext(ht2);  

        javax.sql.DataSource ds = (javax.sql.DataSource)ctx4.lookup("jdbc/ConnectionTest1");  

        System.out.println("Obj was: " + ds.getClass().getName());

        Connection conn=((OracleDataSource)ds).getConnection();

The lookup works, but it fails on the last Connection line with the error :

Exception in thread "main" java.lang.ClassCastException: weblogic.jdbc.common.internal._RemoteDataSource_Stub cannot be cast to oracle.jdbc.pool.OracleDataSource

   -> now that was using  wlclient.jar  in the project properties in Jdeveloper,  wlclient,jar having been copied from the weblogic install.

However if I build wlfullclient.jar  on the weblogic server, copy that over to Jdev and use that instead in the project properties - extra library jar, I get a slightly different error :

Exception in thread "main" java.lang.ClassCastException: weblogic.jdbc.common.internal.RmiDataSource_12120_WLStub cannot be cast to oracle.jdbc.pool.OracleDataSource

This is bog-standard code out of the JDBC developer's guide. so this must surely be some noddy schoolboy error related to wrong versions or jar files or something?

The final S.o.p in the second set of code says  'Obj was: weblogic.jdbc.common.internal.RmiDataSource_12120_WLStub'

so I can understand why the cast is failing,  but the question is how can the code be modified to get this to work?  As said I'm not sure it is even the code at fault because

it is directly lifted from all the standard examples out there..

thanks!!!



Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 24 2014
Added on Jun 26 2014
4 comments
1,061 views