4 Replies Latest reply on Jan 8, 2009 9:08 PM by ezanih

    getting datasource jndi?

      i have written jdbc connection in oracle-ds.xml file how can i get DataSource connection using JNDI in a stateless session bean class with out using xml file/entity/JPA?

        • 1. Re: getting datasource jndi?
          jaikiran

          You will first have to lookup the datasource using the JNDI API. Then you can call the getConnection API on the DataSource. Just an example:

          DataSource ds = (DataSource) new InitialContext().lookup("java:myDS");
          ds.getConnection();


          • 2. Re: getting datasource jndi?

             

            "jaikiran" wrote:
            You will first have to lookup the datasource using the JNDI API. Then you can call the getConnection API on the DataSource. Just an example:
            DataSource ds = (DataSource) new InitialContext().lookup("java:myDS");
            ds.getConnection();

            i wrote the database connection in oracle-ds.xml file and placed in deploy folder and DataSource ds = (DataSource) new InitialContext().lookup("java:myDS");
            ds.getConnection();

            but i didn't get the connection what should i do?

            • 3. Re: getting datasource jndi?

               

              "jaikiran" wrote:
              You will first have to lookup the datasource using the JNDI API. Then you can call the getConnection API on the DataSource. Just an example:
              DataSource ds = (DataSource) new InitialContext().lookup("java:myDS");
              ds.getConnection();

              how can i make jnidi map to datasource?

              • 4. Re: getting datasource jndi?
                ezanih

                Post your oracle-ds.xml and your code. What server are you using ? Because you may have to set some properties before context initialization. Also post your JNDIView (from the JMX Console) if you are using JBoss AS.