7 Replies Latest reply on Dec 4, 2002 11:11 PM by dnoyeb

    Renaming /OracleDS to /comp/env/jdbc/DataSource in JNDI

    ravn

      (I misposted this in the installation forum. Apologies)

      I need to rename the sample OracleDS specified in examples/jca/oracle-service.xml to another JNDI name in order to be able to switch between EJB-containers (a project requirement), by having standardized names.

      It has worked very well just by replacing the URI and username/password and referenced by /OracleDS in JNDI, but I cannot make the new name work. I have tried most combinations of changing the string OracleDS to comp/env/jdbc/DataSource in the XML file, but where the check code says that either jdbc or DataSource is not bound in JNDI.

      Do someone have a oracle-service.xml file where this change has been made I could have a look at? Or point me to the configuration file I need to change?

      Thanks in advance

        • 1. Re: Renaming /OracleDS to /comp/env/jdbc/DataSource in JNDI
          dkato

          Hello ravn,

          I've been working with a Oracle Datasource called "OracleDB" using the template provided with JBoss 3.0 and it's working fine. Although I'm not using the security part yet it goes on very well.
          To access the datasource "OracleDB" I use the followig command:

          DataSource ds =(DataSource) ctx.lookup("jdbc/OracleDB");
          return ds.getConnection();

          but as you can see it calls direcly from the "java:" root context. I'm working on to create a standard like:

          DataSource ds = (DataSource) ctx.lookup("jdbc/OracleDB");
          return ds.getConnection();

          One thing more, you cannot use "comp/env/jdbc/DataSource" because "comp/env/" is the root environment. Try "jdbc/DataSource".

          Here goes the "oracle-service.xml" I'm using, hope it helps.

          []s
          Diogo Catossi

          • 2. Re: Renaming /OracleDS to /comp/env/jdbc/DataSource in JNDI
            pkondaka

            Hey

            Thanks for your input.
            I am also using Oracle DS for my connection.
            I configured oracle-service.xml

            when i put following lines, i am getting error compiling 'DataSource'

            DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/CMISDS");

            can you tell what jar do i need to keep in path

            Thanks
            KPK

            • 3. Re: Renaming /OracleDS to /comp/env/jdbc/DataSource in JNDI
              dkato

              well,

              you need to put on your code:
              import javax.sql.DataSource;

              and be shure that before you call the DataSource you declare the Initial context, like this:

              Context ctx = new InitialContext();
              DataSource ds =(DataSource) ctx.lookup("java:/OracleDS");
              return ds.getConnection()

              to your example:
              Context ic = new InitialContext();
              DataSource ds = (DataSource) ic.lookup("java:jdbc/CMISDS");
              return ds.getConnection()

              *note that I'm suposing you declared "jdbc/CMISDS" as the DataSource's JNDI name.

              • 4. Re: Renaming /OracleDS to /comp/env/jdbc/DataSource in JNDI
                dahan

                I'd like to define a resource reference name in ejb-jar.xml and then define the real jndi name in jboss.xml

                Here is what I did,

                in ejb-jar.xml
                <resource-ref>
                <res-ref-name>jdbc/MySQL</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                <resource-ref>
                in jboss.xml
                <resource-ref>
                <res-ref-name>jdbc/MySQL</res-ref-name>
                <jndi-name>jdbc/DefaultDS</jndi-name>
                </resource-ref>

                Then in my java code I would like to do

                DataSource ds = (DataSource) ctx.lookup("java:jdbc/MySQL");

                to find the data source. I could make this code work in iPlanet App Server, but not in Jboss. Any idea?

                Thanks.

                • 5. Re: Renaming /OracleDS to /comp/env/jdbc/DataSource in JNDI
                  dnoyeb

                  I got that error when I was first learning.

                  DataSource is not a class, you are supposed to replace that with a real class.

                  DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/CMISDS");

                  is just an example the real code should be

                  MyClass ds = (MyClass) ic.lookup("java:comp/env/jdbc/CMISDS");

                  • 6. Re: Renaming /OracleDS to /comp/env/jdbc/DataSource in JNDI
                    dnoyeb

                    Also you might look at my find here. it likely applies to you since I discovered it trying to use my own name for the datasource which was not DefaultDS. but if you already know how to use alternamte names in 3.x maybe its not interesting to you.

                    http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/

                    • 7. Re: Renaming /OracleDS to /comp/env/jdbc/DataSource in JNDI
                      dnoyeb

                      uhh, DataSource is a class :D its just in javax.sql and not in java.sql.....