0 Replies Latest reply on Aug 1, 2012 10:17 PM by colin the aardvark-Oracle

    Cannot lookup oc4j-defined datasource via simple jndi code

    colin the aardvark-Oracle
      Hi all this was originally posted in JDBC but got told to repost it to oc4j. :-)
      (original at Basic JDBC datasource detection question )

      I am using Jdeveloper 11g, oc4j and DB I am investigating different types of very basic jdbc connectivity,
      but cannot get either Managed datasources or native sources to be looked up correctly in JNDI.

      I have included the following jars in my project properties:

      1) oc4j.jar - gotten from the oc4j j2ee/home directory
      2) oc4jclient.jar - ditto
      3) ojdbc5.jar - gotten from the 11g database jdbc directory

      I have created the most basic managed datasoucre in the App Server console, and the most basic native datasource; testing with both against scott tiger on 1521.

      the relevant code snippet and details are as follows :

      Hashtable env = new Hashtable();

      Context initCtx = new InitialContext(env);
      ds = (DataSource) initCtx.lookup("jdbc/ds1");
      conn = ds.getConnection();

      I have tried with the datasource 'ds1' being defined as both a Managed and Native datasource.

      As a managed datasource, the details are:

      Application Name default
      JNDI Location jdbc:oracle:thin:@//localhost:1521/orcl99.example.com
      Type Managed Data Source
      Connection Pool pool1
      Transaction Level Global & Local Transactions

      As a native datasource, the details are :

      Application Name default
      JNDI Location jdbc/ds1
      Type Native Data Source
      Class oracle.jdbc.pool.OracleDataSource
      URL jdbc:oracle:thin:@//localhost:1521/orcl99.example.com

      1) If the datasource is Managed, the exception thrown by the servlet is just a name not found exception:

      [Application AppOc4j1013 deployed to Server Instance IntegratedWebLogicServer]
      Target URL --
      javax.naming.NameNotFoundException: jdbc/ds1 not found
      at com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:60)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at testjdbc.test2.doGet(test2.java:125)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

      .. so I presume this is just a case of me choosing a bad jndi string: jdbc/ds1 but no
      permutation I've tried gets anything else..

      2) If the datasouce is Native, the exception throw is rather more strange :

      [Application AppOc4j1013 deployed to Server Instance IntegratedWebLogicServer]
      Target URL --
      <RMIMessages><EXCEPTION_ORIGINATES_FROM_THE_REMOTE_SERVER> Exception returned by remote server: {0}
      java.io.InvalidClassException: oracle.jdbc.pool.OracleDataSource; local class incompatible: stream classdesc serialVersionUID = -3387215183305991796, local class serialVersionUID = 3349652938965166731
      at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:562)
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1583)

      .. this sounds more like a classloading issue. But the code shown above is in the simplest of servlets,
      using java 1.5 jee 1.5 , jdeveloper 11.

      The 'project' setup in jdeveloper is:

      a local java 1.5 chosen as the default JDK
      oc4j.jar and oc4jclient.jar included (from the local oc4j 10.1.3 server)
      and ojdbc5.jar included from the target database, also local.

      'project technologies' selected are java and JSP&Servlets

      Using Servlet 2.4 and J2ee 1.4

      (trying to make it compatible with oc4j 10.1.3, basically.)

      All clues as to the possibilities for the exceptions appreciated :-)
      best regards and thanks!

      Edited by: colin the aardvark on Jul 16, 2012 7:00 AM