8 Replies Latest reply on Jul 21, 2003 1:28 PM by arupsarkar

    EJB and database connection.

    arupsarkar

      Hi I have created a test ejb and trying to connect to oracle from bean, but I am getting the following error.

      "16:35:03,474 INFO [STDOUT] javax.ejb.EJBException: Unable to connect to databas
      e. jdbc not bound"

      the following is the code.

      private void makeConnection() {

      System.out.println("CustomerBean makeConnection");

      try {
      InitialContext ic = new InitialContext();
      DataSource ds = (DataSource) ic.lookup(CodedNames.MY_DATABASE);
      con = ds.getConnection();
      } catch (Exception ex) {
      throw new EJBException("Unable to connect to database. " +
      ex.getMessage());
      }
      } // makeConnection

      basically CodedNames.MY_DATABASE is as follows:

      public interface CodedNames {

      //public static final String SIEBEL_DATABASE = "java:comp/env/jdbc/OracleDS";
      public static final String MY_DATABASE = "java:/OracleDS";

      }

      I have modified the oracle-service.xml.

      Can someone please advise what piece I am missing.

      Any help is greatly appreciated.

      Regards
      Arup

        • 1. Re: EJB and database connection.

          A resource-ref in your deployment descriptors.

          Regards,
          Adrian

          • 2. Re: EJB and database connection.
            arupsarkar

            Thanks Adrian for replying, I do have a resource-ref in my ejb-jar.xml which is as follows.

            <resource-ref>
            <res-ref-name>java:/OracleDS</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>

            • 3. Re: EJB and database connection.
              raja05

              The initial error message says jdbc not bound, so its still loooking at java:comp/env/jdbc/OracleDS instead of java:/OracleDS which is the physical jndi name,

              Did you compile all ur classes after changing from java:comp/env/jdbc/OracleDS to java:/OracleDS. I know its kinda stupid but just to make sure!!

              Anyway, if you are using java:/OracleDS, you dont even need the resource-ref as you are using hte physical JNDI.

              -Raj

              • 4. Re: EJB and database connection.

                In ejb-jar.xml

                <resource-ref >
                <res-ref-name>jdbc/OracleDS</res-ref-name>
                <res-type>javax.sql.Datasource</res-type>
                <res-auth>Container</res-auth>
                </resource-ref>

                InJboss.xml

                <resource-ref>
                <res-ref-name>jdbc/OracleDS</res-ref-name>
                <jndi-name>java:/OracleDSDS</jndi-name> </resource-ref>

                This will work absolutely fine if you use this String to lookup.
                "java:comp/env/jdbc/OracletDS"

                but if your using "java:/OracleDS" to lookup then you will not require resource-ref-name tag in yr descriptors as pointed by raja in his posting.


                I hope this will get you going.

                • 5. Re: EJB and database connection.
                  arupsarkar

                  Thanks Vishal,

                  I made the changes as you suggested, now I am getting the following error.

                  /************ error **********/

                  13:36:26,298 INFO [STDOUT] CustomerBean makeConnection
                  13:36:26,298 INFO [STDOUT] javax.ejb.EJBException: Unable to connect to databas
                  e. OracletDS not bound
                  13:36:26,308 INFO [STDOUT] Hello! I am Session Bean

                  /************ error **********/

                  I have also attached the piece where I made modification in my oracle-service.xml





                  - <depends optional-attribute-name="ManagedConnectionFactoryName">
                  - <!-- embedded mbean
                  -->
                  -
                  OracleDS
                  -
                  -
                  <config-property name="ConnectionURL" type="java.lang.String">jdbc:oracle:thin:@00.00.000.00:25466:D5791S</config-property>
                  - <!--

                  Here are a couple of the possible OCI configurations.
                  For more information, see http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm

                  <config-property name="ConnectionURL" type="java.lang.String">jdbc:oracle:oci:@youroracle-tns-name</config-property>
                  or
                  <config-property name="ConnectionURL" type="java.lang.String">jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</config-property>

                  Clearly, its better to have TNS set up properly.


                  -->
                  <config-property name="DriverClass" type="java.lang.String">oracle.jdbc.driver.OracleDriver</config-property>
                  - <!-- set these only if you want only default logins, not through JAAS
                  -->
                  <config-property name="scott" type="java.lang.String" />
                  <config-property name="tiger" type="java.lang.String" />


                  • 6. Re: EJB and database connection.

                    Have a look at this thread,

                    http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t= guess is yr url setting for conecting to oracle driver is wrong or may be you need more attributes in there.

                    I hope someone will be able to help you.

                    • 7. Re: EJB and database connection.

                      There is a another thread on 3.2.1
                      I am not sure what version you are using, because with 3.2.1 datasource config file has changed.

                      Have a look at this thead.
                      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=

                      • 8. Re: EJB and database connection.
                        arupsarkar

                        I was using jboss-3.0.6, now I am using jboss-3.2.1, I have modified oracle-ds.xml and put it in the jboss_insatll_dir/server/default/deploy, now I am getting the following error basically could not connect to the database.

                        "15:14:05,566 INFO [STDOUT] javax.ejb.EJBException: Unable to connect to databas
                        e. Table not found:"

                        Regards
                        Arup