예제 #1
0
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    ResultSet rs = null;
    try {
      // SET UP Context environment, to look for Data Pooling Resource
      Context initCtx = new InitialContext();
      Context envCtx = (Context) initCtx.lookup("java:comp/env");
      DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB");
      Connection dbcon = ds.getConnection();

      // ########### SEARCH INPUT PARAMETERS, EXECUTE search
      // #####################################################
      Vector<String> params = new Vector<String>();
      params.add(request.getParameter("fname"));
      params.add(request.getParameter("lname"));
      params.add(request.getParameter("title"));
      params.add(request.getParameter("year"));
      params.add(request.getParameter("director"));

      List<Movie> movies = new ArrayList<Movie>();
      movies = SQLServices.getMovies(params.toArray(new String[params.size()]), dbcon);

      // ########## SET DEFAULT SESSION() PARAMETERS ####################################
      request.getSession().removeAttribute("movies");
      request.getSession().removeAttribute("linkedListMovies");
      request.getSession().removeAttribute("hasPaged");
      request.getSession().setAttribute("hasPaged", "no");
      request.getSession().setAttribute("movies", movies);
      request.getSession().setAttribute("currentIndex", "0");
      request.getSession().setAttribute("defaultN", "5");

      // ########## IF MOVIES FROM SEARCH NON-EMPTY ###########################################
      List<String> fields = Movie.fieldNames();
      int count = 1;
      if (!movies.isEmpty()) {
        request.setAttribute("movies", movies);
        for (String field : fields) {
          request.setAttribute("f" + count++, field);
        }
        request.getRequestDispatcher("../movieList.jsp").forward(request, response);
      } else {
        out.println("<html><head><title>error</title></head>");
        out.println("<body><h1>could not find any movies, try your search again.</h1>");
        out.println("<p> we are terribly sorry, please go back. </p>");
        out.println("<table border>");
        out.println("</table>");
      }
      dbcon.close();

    } catch (SQLException ex) {
      while (ex != null) {
        System.out.println("SQL Exception:  " + ex.getMessage());
        ex = ex.getNextException();
      }
    } catch (java.lang.Exception ex) {
      out.println(
          "<html>"
              + "<head><title>"
              + "moviedb: error"
              + "</title></head>\n<body>"
              + "<p>SQL error in doGet: "
              + ex.getMessage()
              + "</p></body></html>");
      return;
    }
    out.close();
  }
예제 #2
0
  public String[] send() {
    String ret[] = {"0", "internal_problem"};

    if (!this.validateInput()) {
      ret[1] = "input_error";
      return ret;
    }

    Connection con = null;
    try {

      con = DbCon.getConnection();
      con.setAutoCommit(false);
      String sql =
          "select c.acc_no, t.status from customer c, tsel_cust_account t where c.msisdn = ? and t.acc_no = c.acc_no";
      PreparedStatement ps = con.prepareStatement(sql);
      ps.setString(1, this.msisdn);
      ResultSet rs = ps.executeQuery();
      String acc_no = "";
      String status = "";

      boolean b1 = false;
      boolean b2 = false;
      boolean b3 = false;
      if (rs.next()) {
        acc_no = rs.getString(1);
        b1 = true;
        status = rs.getString(2);
        if (status != null && status.equals("1")) {
          b2 = true;
        } else {
          ret[1] = "account_not_active";
        }
      }

      rs.close();
      ps.close();

      double balance_cust = 0;
      double balance_merchant = 0;

      if (b1 && b2) {
        sql = "select * from tsel_cust_account where acc_no = ? for update";
        ps = con.prepareStatement(sql);
        ps.setString(1, acc_no);
        rs = ps.executeQuery();
        if (rs.next()) {
          b3 = true;
          balance_cust = rs.getDouble("balance");
        } else {
          throw new Exception("acc_no not found " + msisdn + " accno:" + acc_no);
        }
        rs.close();
        ps.close();

        if (b3) {
          sql = "update tsel_cust_account set balance=balance+? where acc_no = ?";
          ps = con.prepareStatement(sql);
          ps.setString(1, this.amount);
          ps.setString(2, acc_no);
          ps.executeUpdate();

          String db_trxid = this.getId(con);

          // history tsel_account
          sql =
              "insert into tsel_cust_account_history values(?, ?, ?, ?, ?, ?, ?, sysdate, ?, ?, ?)";
          ps = con.prepareStatement(sql);
          ps.setString(1, db_trxid);
          ps.setString(2, "txid");
          ps.setString(3, acc_no);
          ps.setString(4, String.valueOf(UssdTx.TSEL_CASH_IN));
          ps.setString(5, "0");
          ps.setString(6, this.amount);
          ps.setDouble(7, (balance_cust + Double.parseDouble(this.amount)));
          ps.setString(8, this.loadingTerminalId);
          ps.setString(9, "");
          ps.setString(10, this.userlogin);
          ps.executeUpdate();
          ps.close();

          // end of history tsel_account

          // merchant_id, merchant_acc

          String merchant_acc_no = "";
          sql =
              "select m.acc_no from merchant m, loading_terminal l where terminal_id = ? and l.merchant_id = m.merchant_id";
          ps = con.prepareStatement(sql);
          ps.setString(1, this.loadingTerminalId);
          rs = ps.executeQuery();
          if (rs.next()) {

            merchant_acc_no = rs.getString(1);

          } else {

            throw new Exception("merchantid not found " + this.loadingTerminalId);
          }
          rs.close();
          ps.close();

          sql = "select balance from tsel_merchant_account where acc_no = ? for update ";
          ps = con.prepareStatement(sql);
          ps.setString(1, merchant_acc_no);
          rs = ps.executeQuery();
          if (rs.next()) {
            balance_merchant = rs.getDouble(1);
          } else {
            throw new Exception("merchant_acc_no not exist");
          }

          rs.close();
          ps.close();

          sql = "update tsel_merchant_account set balance=balance-? where acc_no = ?";
          ps = con.prepareStatement(sql);
          ps.setString(1, this.amount);
          ps.setString(2, merchant_acc_no);
          ps.executeUpdate();
          ps.close();

          sql =
              "insert into tsel_merchant_account_history values(?, ?, ?, ?, ?, ?, ?, ?, sysdate, ?, ?, ?)";
          ps = con.prepareStatement(sql);
          ps.setString(1, db_trxid);
          ps.setString(2, "txid");
          ps.setString(3, merchant_acc_no);
          ps.setString(4, this.msisdn);
          ps.setString(5, String.valueOf(UssdTx.TSEL_CASH_IN));
          ps.setString(6, this.amount);
          ps.setString(7, "0");
          ps.setDouble(8, (balance_merchant - Double.parseDouble(this.amount)));
          ps.setString(9, this.loadingTerminalId);
          ps.setString(10, "");
          ps.setString(11, this.userlogin);
          ps.executeUpdate();
          ps.close();
          // end of merchant_account history
          con.commit();
          ret[0] = "1";
          ret[1] = "Success";

        } else {
          con.rollback();
        }

      } else {
        if (!b1) {
          ret[1] = "account_not_found";
        }
        con.rollback();
      }

    } catch (Exception e) {
      e.printStackTrace(System.out);
      try {
        con.rollback();
      } catch (Exception e2) {
      }

    } finally {
      if (con != null) {
        try {
          con.setAutoCommit(true);
        } catch (Exception e4) {
        }
      }
      if (con != null) {
        try {
          con.close();
        } catch (Exception e3) {
        }
      }
    }

    return ret;
  }
예제 #3
0
  /**
   * Perrform process.
   *
   * @return Message that would be set to process infor summary (no use currently)
   * @throws Exception if not successful
   */
  protected String doIt() throws Exception {
    // 	load query into cache file directly
    // int userId= this.getAD_User_ID();
    // User user= SecurityUtils.getUser(userId);

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    QueryEngine engine = QueryEngine.getInstance();
    conn = engine.getConnection();

    Configurations conf =
        (Configurations)
            WebUtils.getServletContextManager().getActor(nds.util.WebKeys.CONFIGURATIONS);
    String folder = conf.getProperty("ahyy.payment.folder.download", "e:/act/ahyy/download");
    File fd = new File(folder);
    if (!fd.exists()) fd.mkdirs();
    ahyyCode = conf.getProperty("ahyy.payment.code");
    if (ahyyCode == null || ahyyCode.length() != 8)
      throw new NDSException("Wrong code for bank payment interface");

    SimpleDateFormat df = new SimpleDateFormat("yyMMdd");
    String ftpFile = "MPAYREP" + ahyyCode + df.format(new java.util.Date());
    String file = folder + "/" + ftpFile;
    StringBuffer sb = new StringBuffer();
    String lineSep = Tools.LINE_SEPARATOR;
    try {
      // 下载文件
      CommandExecuter cmd = new CommandExecuter(folder + "/log/" + ftpFile + ".log");
      String exec = conf.getProperty("ahyy.payment.download", "e:/act/bin/download.cmd");
      int err = cmd.run(exec + " " + ftpFile);
      if (err != 0) {
        throw new NDSException("Error(code=" + err + ") when doing " + exec + " " + ftpFile);
      }
      if (!(new File(file)).exists()) {
        throw new NDSException("File not downloaded when doing " + exec + " " + ftpFile);
      }
      BufferedReader in = new BufferedReader(new FileReader(file));
      in.readLine(); // skip first line, which is summary
      String line = in.readLine();
      pstmt =
          conn.prepareStatement(
              "update b_pay_sum set state=?, err_code =? where billno=? and state='R'");
      while (line != null) {
        log.debug(line);
        if (line.length() < 34) {
          log.debug("line not has length: 34");
        }

        /*
        String billType= line.substring(0,2);
        String billNo= line.substring(0, 22);// billno
        String amt=line.substring(22,34);
        String ack=line.substring(34,36);*/
        String billNo = line.substring(0, 20); // billno
        String amt = line.substring(20, 32);
        String ack = line.substring(32, 34);
        if ("00".equals(ack)) {
          java.math.BigDecimal bd = new java.math.BigDecimal(amt);
          pstmt.setString(1, "Y");
          pstmt.setNull(2, java.sql.Types.VARCHAR);
          pstmt.setString(3, billNo);
          int ret = pstmt.executeUpdate();
          if (ret != 1) {
            sb.append(line + "(updated " + ret + " lines)").append(lineSep);
          }
        } else {
          pstmt.setString(1, "P");
          pstmt.setString(2, ack);
          pstmt.setString(3, billNo);
          int ret = pstmt.executeUpdate();
          if (ret != 1) {
            sb.append(line + "(updated " + ret + " lines)").append(lineSep);
          }
        }
        line = in.readLine();
      }
      in.close();
      try {
        log.debug("Move " + file + " to " + folder + "/log/" + ftpFile);
        (new File(file)).renameTo(new File(folder + "/log/" + ftpFile));
      } catch (Throwable t) {
        log.error("Fail to move " + file + " to " + folder + "/log/" + ftpFile, t);
      }
      Vector vet = new Vector();
      String log = sb.toString();
      this.log.debug(log);
      this.addLog(log);
      return "完成";
    } finally {
      if (rs != null)
        try {
          rs.close();
        } catch (Throwable t) {
        }
      if (pstmt != null)
        try {
          pstmt.close();
        } catch (Throwable t) {
        }
      if (conn != null)
        try {
          conn.close();
        } catch (Throwable t) {
        }
    }
  }