7 Replies Latest reply on Aug 15, 2003 9:27 AM by divine_comedy

    My Problem of Using Oracle as DataSource

    sakyamuni

      I want to use Oracle as DataSource, My Jboss Version is 3.0.7
      I dropped the docs\example\jca\oracle-service.xml in the deploy dir and jboss console shows success:
      [MainDeployer] Starting deployment of package: file:/C:/jboss-3.0.7/server/all/deploy/oracle-service.xml
      [JBossManagedConnectionPool] Creating
      [JBossManagedConnectionPool] Created
      [LocalTxConnectionManager] Creating
      [LocalTxConnectionManager] Created
      [JBossManagedConnectionPool] Starting
      [JBossManagedConnectionPool] Started
      [LocalTxConnectionManager] Starting
      [OracleDS] Bound connection factory for resource adapter 'JBoss LocalTransaction JDBC Wrapper' to JNDI name 'java:/OracleDS'
      [LocalTxConnectionManager] Started
      [MainDeployer] Deployed package: file:/C:/jboss-3.0.7/server/all/deploy/oracle-service.xml

      but How can I use this connection pool?
      My codes:
      Properties pr = new Properties();
      pr.put(InitialContext.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      pr.put(InitialContext.PROVIDER_URL, "127.0.0.1:1099");
      InitialContext initialContext = new InitialContext(pr);
      DataSource ds = (DataSource) initialContext.lookup("OracleDS");
      Connection conn = ds.getConnection();

      Error:
      javax.naming.NameNotFoundException: OracleDS not bound

      what's the problem?
      thanks alot!

        • 1. Re: My Problem of Using Oracle as DataSource
          mharnvi

          Try

          initialContext.lookup("java:/OracleDS");

          • 2. Re: My Problem of Using Oracle as DataSource
            debbie

            Hi,
            i'm a newbie and for the couple of days i too was struggling with same prob as the one you've mentioned. Well, i've finally found a way out.

            use :
            1. DataSource ds = (DataSource) initialContext.lookup("java:/OracleDS");

            2. change ur ejb-jar.xml file to include:
            <resource-ref>
            <res-ref-name>java:/OracleDS</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Application</res-auth>
            </resource-ref>

            3. change ur jboss.xml file to include:
            <resource-ref>
            <res-ref-name>java:/OracleDS</res-ref-name>
            <res-jndi-name>OracleDS</res-jndi-name>
            </resource-ref>


            4. Also drop the classes12.jar into the deploy directory

            I don't whether this is the most elegant solution around but atleast it works.

            - debbie

            • 3. Re: My Problem of Using Oracle as DataSource
              sakyamuni

              thanks, but I don't use Ejb to connect the DataSource, I just want to use an application to get this connection, How can I do this?
              In JNDIView, I found "OracleDS" was in java:namespace(not in Global JNDI NameSpcace), my another question is: how Can I put "OracleDS" in Global JNDI NameSpace(not namespace)?

              • 4. Re: My Problem of Using Oracle as DataSource
                javierdajabon

                Sakyamuni,
                It seems like what you are trying to do is to get a reference to that datasource from 'outside' of JBoss or on a different JVM (I believe that is the proper terminology). That is not possible. You could only get a reference to that datasource from an EJB,JSP,Servlet,etc. that has been deployed on JBoss.
                Anyone, please correct me if I am wrong.
                Javier

                • 5. Re: My Problem of Using Oracle as DataSource
                  divine_comedy

                  You can't get a DataSource from a different VM.

                  • 6. Re: My Problem of Using Oracle as DataSource
                    sakyamuni

                    Now I get the answer of my question from you, thank you all. I can use the connection pool in my Ejb, not an application, and I try to return the connection to my client , the JVM tell me that this connection must be Serializable.

                    • 7. Re: My Problem of Using Oracle as DataSource
                      divine_comedy

                      I believe it's also not possible to return the connection to a different VM. Returning DataSource + Connection to a different VM is not good practice IMHO. What you should probably do is set up a DataSource on the client side. May I know the reason why you would want to return a connection to the client ? If you need to call a Statement ( Prepared, Callable, etc ) maybe you should delegate the call to a SessionBean or something.