3 Replies Latest reply on Jan 4, 2005 6:03 PM by lafr

    jdbc not bound

    barunkdas

      hi all,

      i am using Eclipse as my IDE, JBoss as my AS, Postgres as my Database server. when i am trying to connect database from my action class its get connected but when i'm using EJB and trying to connect i get error "javax.naming.NameNotFoundException: jdbc not bound". i'm having class to get connection. code is as simple as

      Context ctx = new InitialContext();
      DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/myCoreDS");
      Connection conn = ds.getConnection();

      Please help me cause i've spent lots of time and i have not got any thing useful.

      Thanking you in advance.

        • 1. Re: jdbc not bound
          mario202

          Hi

          Have you deployed your Postgres - data source definition?

          Here a sample...

          Data Source definition File:
          /jboss-4.0.0/server/default/deploy/postgres-ds.xml
          Note that the name of the data source definition file must end with -ds.xml

          <?xml version="1.0" encoding="UTF-8"?>
          
          <!-- ===================================================================== -->
          <!-- -->
          <!-- JBoss Server Configuration -->
          <!-- -->
          <!-- ===================================================================== -->
          
          <!-- $Id: postgres-ds.xml,v 1.3 2004/09/15 14:37:40 loubyansky Exp $ -->
          <!-- ==================================================================== -->
          <!-- Datasource config for Postgres -->
          <!-- ==================================================================== -->
          
          
          <datasources>
           <local-tx-datasource>
           <jndi-name>PostgresDS</jndi-name>
           <connection-url>jdbc:postgresql://localhost:5432/jdb?autoReconnect=true</connection-url>
           <driver-class>org.postgresql.Driver</driver-class>
           <user-name>juser</user-name>
           <password>jpw</password>
           <!-- sql to call when connection is created
           <new-connection-sql>some arbitrary sql</new-connection-sql>
           -->
          
           <!-- sql to call on an existing pooled connection when it is obtained from pool
           <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
           -->
          
           <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
           <metadata>
           <type-mapping>PostgreSQL 7.2</type-mapping>
           </metadata>
           </local-tx-datasource>
          
          </datasources>
          



          • 2. Re: jdbc not bound
            viktor_i

            Did you try
            DataSource ds = (DataSource) ctx.lookup("java:jdbc/myCoreDS");

            • 3. Re: jdbc not bound
              lafr

              The jndi-name of your datasource is combined of "java:" and the jndi-name from the -ds.xml file.
              Take a look at jmx-console/JNDIView to see what's available.