/** Tasks to be carried out in the STARTUP_EVENT. Logs a message */
  private void onStartTask() {
    ctx.log("LifecycleTopic: STARTUP_EVENT");
    // my code
    QueueSession qsession[] = new QueueSession[10];
    Queue queue[] = new Queue[10];

    try {
      for (int i = 0; i < 10; i++) {
        // Get initial context
        ctx.log("Get initial context");
        InitialContext initialContext = new InitialContext();

        // look up the connection factory from the object store
        ctx.log("Looking up the queue connection factory from JNDI");
        QueueConnectionFactory factory =
            (QueueConnectionFactory) initialContext.lookup("jms/QCFactory");

        // look up queue from the object store
        ctx.log("Create queue connection");
        QueueConnection qconn = factory.createQueueConnection();

        ctx.log("Create queue session");
        qsession[i] = qconn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        ctx.log("Looking up the queue from JNDI");
        queue[i] = (Queue) initialContext.lookup("jms/SampleQueue");
      }

      updateDB();

    } catch (Exception e) {
      ctx.log("Exception caught in test code");
      e.printStackTrace();
    }

    // end my code

    // my code
    // createAccount();
    // end my code
  }
Ejemplo n.º 2
0
  public ResultSet getPrefixName() throws SQLException, NamingException {

    String sql_PrefixName = "SELECT prefix_id,prefixname,abbreviation FROM hex.ref_prefixname";

    ctx = new InitialContext();
    ds = (DataSource) ctx.lookup("jdbc/HEX");
    conn = ds.getConnection();
    pstmt = conn.prepareStatement(sql_PrefixName);
    rs = pstmt.executeQuery();

    return rs;
  }
  public Connection getConnection() throws Exception {
    InitialContext ctx = null;
    ctx = new InitialContext();

    if (getDataSourceJndiName() == null)
      throw (new Exception("Data Source JNDI name is null. Check whether the JNDI name is null."));

    DataSource ds = (javax.sql.DataSource) ctx.lookup(getDataSourceJndiName());
    Connection conn = ds.getConnection();

    return conn;
  }
Ejemplo n.º 4
0
  /**
   * Constructor encargado de iniciar el contexto y el objeto DataSource.
   *
   * @param dataSourceName Nombre del DataSource que se empleará
   * @throws Exception La excepción que puede arrojarse se debe a que no se cree el objeto
   *     DataSource.
   */
  public DbConnection(String dataSourceName) throws Exception {
    try {
      this.dataSourceName = dataSourceName;
      InitialContext iCtx = new InitialContext();
      this.dataSource = (javax.sql.DataSource) iCtx.lookup(dataSourceName);
    } catch (Exception e) {
      // System.out.print("Error en constructor de DBConnection: "+e.getMessage());

      StringWriter sw = new StringWriter();
      e.printStackTrace(new PrintWriter(sw));
      String msg = sw.toString();
      // System.out.print("Error en constructor de DBConnection: " + msg);

      e.printStackTrace();
    }
  }
Ejemplo n.º 5
0
 public static Connection getConnect() throws SQLException, NamingException {
   InitialContext ic = new InitialContext();
   DataSource ds = (DataSource) ic.lookup("java:/comp/env/jdbc/chatdb");
   return ds.getConnection();
 }
Ejemplo n.º 6
0
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;
      _jspx_resourceInjector =
          (org.apache.jasper.runtime.ResourceInjector)
              application.getAttribute("com.sun.appserv.jsp.resource.injector");

      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write(" ");

      DataSource ds = null;
      Connection con = null;
      PreparedStatement ps = null;
      InitialContext ic;
      try {
        ic = new InitialContext();
        ds = (DataSource) ic.lookup("java:/jdbc/AVMS");
        // ds = (DataSource)ic.lookup( "java:/jboss" );
        con = ds.getConnection();
        ps = con.prepareStatement("SELECT * FROM dbo.ROLE");
        // pr = con.prepareStatement("SELECT * FROM dbo.JMS_USERS");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
          out.println("<br> " + rs.getString("role_name") + " | " + rs.getString("role_desc"));
          // out.println("<br> " +rs.getString("USERID") + " | " +rs.getString("PASSWD"));
        }
        rs.close();
        ps.close();
      } catch (Exception e) {
        out.println("Exception thrown :: " + e);
      } finally {
        if (con != null) {
          con.close();
        }
      }
      out.write('\n');
      out.write('\n');
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0) out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }