2 Replies Latest reply on Sep 23, 2008 10:26 AM by jaikiran

    Need help in naming the datasource files?

      Please help me, I am a newbie…..

      I have a class which is looking for JNDI in Jboss, I have deployed the jar file for this project in Jboss deploy directory.
      Can any one explain me, where should I place my datasource xml file, i.e should I place it in the deploy directory itself?
      What should I name the XML files?
      Upon seeing the files I thought I should name them as
      proxy-ds.xml, proxy-backup-ds.xml, web-ds.xml.
      Am I right? Or should I name it differently?



      public enum ProxyDbMode {PRIMARY, BACKUP};
      private ProxyDbMode proxyMode = ProxyDbMode.PRIMARY;

      private Connection getProxyDbConnection() throws ErpProxyDaoException, SQLException {

      Connection con;

      if (this.proxyMode != ProxyDbMode.PRIMARY) {
      con = this.connectToDatabase("proxy");
      ErpProxyProgressDAO.logger.info("Connected to proxy primary");
      }
      else {
      con = this.connectToDatabase("proxy-backup");
      ErpProxyProgressDAO.logger.info("Connected to proxy backup");
      }

      return con;
      }

      private Connection getQadWebDbConnection() throws ErpProxyDaoException, SQLException {
      Connection con = this.connectToDatabase("web");
      ErpProxyProgressDAO.logger.info("Connected to web db");
      return con;
      }


      private Connection connectToDatabase(String name) throws ErpProxyDaoException, SQLException{

      Context ctx = null;
      DataSource ds = null;
      try{
      ctx = new InitialContext();
      ds = (DataSource) ctx.lookup("java:" + name + "-ds");
      }catch(Exception e){
      throw new ErpProxyDaoException("to throw NamingException -- ", e);
      }

      return ds.getConnection();
      }
      ------------------------------------------------------------------------------------
      And how should I make sure that the connection closes, when ever I call this Method?

      Thanks for taking time and looking at my question. Please respond......