1 Reply Latest reply on Oct 7, 2008 1:25 PM by peterj

    How to name my JNDI(progress Connection pool) and call it?

      Hi,

      I want to setup connection pooling in JBossAS for Progress database.
      I am not able to acess this JNDI? can anybody point out he problem in my code or in my xml file?

      Are there any good practices that should be followed in
      1) naming the XML file, and how does jboss locate particular JNDI
      2) how to name the <jndi-name> in the XML file
      3) how to lookup the jndi using java code?
      I got confused seeing various codes
      one says use "java:comp/name"
      other says "java:name"
      Seeing at my code can anybody explain how should I call the jndi?


      Please............



      I have a web-ds.xml file deployed in server/all/deploy

      <?xml version="1.0" encoding="UTF-8"?>

      <!-- ===================================================================== -->
      <!-- JBoss Server Configuration -->
      <!-- $Id: qadWeb-ds.xml 63175 2007-05-21 16:26:06Z rrajesh $ -->
      <!-- Datasource config for Progress 9.1 -->



      <local-tx-datasource>
      <jndi-name>web</jndi-name>

      <connection-url>jdbc:JdbcProgress:T:qad3:15330:trnwebeb2</connection-url>
      <driver-class>com.progress.sql.jdbc.JdbcProgressDriver</driver-class>
      <user-name>xxxx</user-name>
      yyyyy

      <min-pool-size>5</min-pool-size>

      <!-- The maximum connections in a pool/sub-pool -->
      <max-pool-size>20</max-pool-size>

      <idle-timeout-minutes>20</idle-timeout-minutes>
      <!-- sql to call on an existing pooled connection when it is obtained from pool-->
      <check-valid-connection-sql>SELECT COUNT(1) FROM pub.zzad_ctrl</check-valid-connection-sql>

      <track-statements>true</track-statements>-->

      <!-- HSQL DB benefits from prepared statement caching -->
      <prepared-statement-cache-size>32</prepared-statement-cache-size>

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->

      <type-mapping>PostgreSQL 7.2</type-mapping>

      </local-tx-datasource>




      And the code to acess it
      private Connection connectToDatabase(String name) throws ErpProxyDaoException, SQLException{

      Connection con=null;
      Context ctx = null;
      DataSource ds = null;
      try{
      logger.info("before loading the datasource");
      logger.info("the database I'm connecting to is :" + name);
      ctx = new InitialContext();
      ds = (DataSource) ctx.lookup("java:/" + name);
      logger.info("After loading the datasource: " + ds);
      con=ds.getConnection();
      }catch(Exception e){
      throw new ErpProxyDaoException("to throw NamingException -- ", e);
      }
      return con;
      }

        • 1. Re: How to name my JNDI(progress Connection pool) and call i
          peterj

          According to your web-ds.xml file, you can look up the datasource using the name "":

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

          if that doesn't work, try "java:/web" (even I get confused as to whether the slash is required).

          If you want to look up the datasource using your naming context (that is, via "java:/comp/env"), then you need to add the following to WEB-INF/web.xml:

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


          and the following to WEB-INF/jboss-web.xml:

          <resource-ref>
           <res-ref-name>web1</res-ref-name>
           <jndi-name>java:web</jndi-name>
           </resource-ref>


          Then in your code use:

          ds = (DataSource) ctx.lookup("java:/comp/env/web1");

          I changed the name in the code to 'web1' so that you could see how that maps to the web.xml, which in turn maps to the jboss-web.xml, which in turn changes the name to simply 'web' which then matches the name in the *-ds.xml file.