Exemplo n.º 1
0
  public String updateStatus(String new_status) {

    String back = "";

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String str = "";
    String qq = "";
    con = Helper.getConnection();
    if (con == null) {
      back = "Could not connect to DB";
      addError(back);
      return back;
    }
    try {
      qq = "update monitors set status=? where id = ? ";
      if (debug) {
        logger.debug(qq);
      }
      pstmt = con.prepareStatement(qq);
      pstmt.setString(1, new_status);
      pstmt.setString(2, id);
      pstmt.executeUpdate();
    } catch (Exception ex) {
      back += ex + ":" + qq;
      logger.error(back);
      addError(back);
    } finally {
      Helper.databaseDisconnect(con, pstmt, rs);
    }
    return back;
  }
Exemplo n.º 2
0
  protected boolean ejecutarActualizacionSQL(String comandoSQL) throws Exception {
    boolean ok;
    if (this.conectar()) {
      // La consulta es preparada porque requiere de parametros
      // por ejemplo:
      // delete from producto where precio=?
      // insert into producto values (?,?,?,?,?)
      // los ? indican parametros ordenados por posicion
      PreparedStatement sql = this.conexión.prepareStatement(comandoSQL);

      // System.err.println(comandoSQL+"-->");
      /*for(int i=1;parametros.hasNext();i++){
      	String parametro= parametros.next().toString();
      	sql.setString(i,parametro);
      	//System.err.println("param["+i+"]="+parametro);
      }*/

      ok = sql.executeUpdate() != 0;

      // importante cerrar la conexión
      sql.close();
      sql = null;
      this.desconectar();

      return ok;
    } else return false;
  } // Fin ejecutarSQL
Exemplo n.º 3
0
  public String doDelete() {

    String back = "", qq = "";

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    con = Helper.getConnection();
    if (con == null) {
      back = "Could not connect to DB";
      addError(back);
      return back;
    } else {
      try {
        qq = "delete from monitors where id=?";
        if (debug) {
          logger.debug(qq);
        }
        pstmt = con.prepareStatement(qq);
        pstmt.setString(1, id);
        pstmt.executeUpdate();
        message = "Deleted Successfully";
      } catch (Exception ex) {
        back += ex + ":" + qq;
        logger.error(back);
        addError(back);
      } finally {
        Helper.databaseDisconnect(con, pstmt, rs);
      }
    }
    return back;
  }
Exemplo n.º 4
0
 public String updateImport(PreparedStatement pstmt) {
   String msg = "";
   try {
     int jj = 1;
     if (device_id.equals("")) pstmt.setNull(jj++, Types.INTEGER);
     else pstmt.setString(jj++, device_id);
     if (name.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
     else pstmt.setString(jj++, name);
     if (serial_num.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
     else pstmt.setString(jj++, serial_num);
     if (model.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
     else pstmt.setString(jj++, model);
     if (type.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
     else pstmt.setString(jj++, type);
     if (vertical_resolution.equals("")) pstmt.setNull(jj++, Types.INTEGER);
     else pstmt.setString(jj++, vertical_resolution);
     if (horizontal_resolution.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
     else pstmt.setString(jj++, horizontal_resolution);
     if (manufacturer.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
     else pstmt.setString(jj++, manufacturer);
     pstmt.setString(jj++, external_id);
     pstmt.executeUpdate();
   } catch (Exception ex) {
     msg += "update " + ex;
     logger.error(external_id + " " + ex);
     // System.err.println(id+" "+ex);
   }
   return msg;
 }
Exemplo n.º 5
0
  public String doPartialUpdate() {

    String back = "";
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String str = "";
    String qq = "";
    con = Helper.getConnection();
    if (con == null) {
      back = "Could not connect to DB";
      addError(back);
      return back;
    }
    try {
      qq =
          "update monitors set "
              + "asset_num=?, screen_size=?,received=?, expected_age=?, "
              + "notes=? "
              + "where id=?";

      if (debug) {
        logger.debug(qq);
      }
      pstmt = con.prepareStatement(qq);
      int jj = 1;
      if (asset_num.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
      else pstmt.setString(jj++, asset_num);
      if (screen_size.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
      else pstmt.setString(jj++, screen_size);
      if (received.equals("")) pstmt.setNull(jj++, Types.DATE);
      else pstmt.setDate(jj++, new java.sql.Date(dateFormat.parse(received).getTime()));
      pstmt.setString(jj++, "" + expected_age);
      if (notes.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
      else pstmt.setString(jj++, notes);
      pstmt.setString(6, id);
      pstmt.executeUpdate();
    } catch (Exception ex) {
      back += ex + ":" + qq;
      logger.error(back);
      addError(back);
    } finally {
      Helper.databaseDisconnect(con, pstmt, rs);
    }
    if (back.equals("")) {
      back = doSelect();
    }
    return back;
  }
Exemplo n.º 6
0
  public String doSave() {

    String back = "";

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String qq =
        "insert into monitors values(0,?," + "?,?,?,?,?," + "?,?,?,?,?," + "?,?,'Active',?,'y')";
    editable = "y";
    con = Helper.getConnection();
    if (con == null) {
      back = "Could not connect to DB";
      addError(back);
      return back;
    } else {
      try {
        pstmt = con.prepareStatement(qq);
        if (debug) {
          logger.debug(qq);
        }
        back = fillPStatement(pstmt);
        if (back.equals("")) {
          pstmt.executeUpdate();
          //
          // get the id of the new record
          //
          qq = "select LAST_INSERT_ID() ";
          if (debug) {
            logger.debug(qq);
          }
          pstmt = con.prepareStatement(qq);
          rs = pstmt.executeQuery();
          if (rs.next()) {
            id = rs.getString(1);
          }
          message = "Saved Successfully";
        }
      } catch (Exception ex) {
        back += ex;
        logger.error(ex);
        addError(back);
      } finally {
        Helper.databaseDisconnect(con, pstmt, rs);
      }
    }
    return back;
  }
Exemplo n.º 7
0
  public String doUpdate() {

    String back = "";

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String str = "";
    String qq = "";
    con = Helper.getConnection();
    if (con == null) {
      back = "Could not connect to DB";
      addError(back);
      return back;
    }
    try {
      qq =
          "update monitors set external_id=?,device_id=?,"
              + "name=?,asset_num=?,serial_num=?,screen_size=?,model=?,type=?,"
              + "vertical_resolution=?,horizontal_resolution=?,manufacturer=?,"
              + "received=?,expected_age=?, "
              + "notes=? "
              + // we do not change status here
              "where id=?";

      if (debug) {
        logger.debug(qq);
      }
      pstmt = con.prepareStatement(qq);
      back = fillPStatement(pstmt);
      if (back.equals("")) {
        pstmt.setString(15, id); // 17 - 2 (editable)
        pstmt.executeUpdate();
      }
    } catch (Exception ex) {
      back += ex + ":" + qq;
      logger.error(back);
      addError(back);
    } finally {
      Helper.databaseDisconnect(con, pstmt, rs);
    }
    if (back.equals("")) {
      back = doSelect(); // to get status
    }
    return back;
  }
Exemplo n.º 8
0
  /**
   * This method Inserts Journal Dates in BLG_PRD table.
   *
   * @exception SQLException, if Insertion fails
   * @author
   */
  public boolean insertJrnldts(
      String bpid,
      String blgsys,
      String rgn,
      String strtdt,
      String enddt,
      String month,
      String year) {
    String query;
    boolean insert_flag = false;
    PreparedStatement pstmt = null;

    query =
        "Insert into blg_prd (bp_id,bs_id_fk,bp_year,bp_month,bp_strt_dat,bp_end_dat,bp_rgn) values ";
    query = query + "(?,?,?,?,to_date(?,'MM/DD/YYYY') ,to_date(?,'MM/DD/YYYY') ,?) ";

    USFEnv.getLog().writeDebug("Dinvjrnl:Insertion - Query" + query, this, null);

    try {
      pstmt = conn.prepareStatement(query);
      pstmt.setString(1, bpid);
      pstmt.setString(2, blgsys);
      pstmt.setString(3, year);
      pstmt.setString(4, month);
      pstmt.setString(5, strtdt);
      pstmt.setString(6, enddt);
      pstmt.setString(7, rgn);

      insert_flag = (pstmt.executeUpdate() != 0) ? true : false;
      if (pstmt != null) pstmt.close();
      return insert_flag;
    } catch (SQLException ex) {
      USFEnv.getLog().writeCrit("Dinvjrnl: The Insertion of Journal Dates failed", this, ex);
      try {
        if (pstmt != null) pstmt.close();
      } catch (SQLException e) {
        USFEnv.getLog().writeCrit("Unable to close the resultset/prepared statement", this, e);
      }
    }
    return false;
  }
Exemplo n.º 9
0
  public String saveImport(PreparedStatement pstmt) {
    String msg = "";
    try {
      int jj = 1;

      pstmt.setString(jj++, external_id);
      if (device_id.equals("")) pstmt.setNull(jj++, Types.INTEGER);
      else pstmt.setString(jj++, device_id);
      if (name.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
      else pstmt.setString(jj++, name);
      // asset_num = null
      if (serial_num.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
      else pstmt.setString(jj++, serial_num);
      // screen_size = null
      if (model.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
      else pstmt.setString(jj++, model);
      //
      if (type.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
      else pstmt.setString(jj++, type);
      if (vertical_resolution.equals("")) pstmt.setNull(jj++, Types.INTEGER);
      else pstmt.setString(jj++, vertical_resolution);
      if (horizontal_resolution.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
      else pstmt.setString(jj++, horizontal_resolution);
      if (manufacturer.equals("")) pstmt.setNull(jj++, Types.VARCHAR);
      else pstmt.setString(jj++, manufacturer);
      //
      if (received.equals("")) pstmt.setNull(jj++, Types.DATE);
      else pstmt.setString(jj++, received); // as text
      // expected_age = null
      // status = 'Active'
      // notes = null
      // editable = null
      pstmt.executeUpdate();
    } catch (Exception ex) {
      msg += " Save " + ex;
      // System.err.println(id+" "+ex);
      logger.error(external_id + " " + ex);
    }
    return msg;
  }
Exemplo n.º 10
0
  /**
   * This method updates the BLG_PRD table.
   *
   * @exception SQLException, if query fails
   * @author
   */
  public boolean updateJrnldts(String bpid, String strtdt, String enddt) {
    String query;
    boolean update_flag = false;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    query =
        "update blg_prd set bp_strt_dat=to_date(?,'MM/DD/YYYY') , bp_end_dat=to_date(?,'MM/DD/YYYY') where bp_id = ?";

    USFEnv.getLog().writeDebug("Dinvjrnl:Updation- Query" + query, this, null);

    try {
      pstmt = conn.prepareStatement(query);
      pstmt.setString(1, strtdt);
      pstmt.setString(2, enddt);
      pstmt.setString(3, bpid);

      update_flag = (pstmt.executeUpdate() != 0) ? true : false;
      if (pstmt != null) pstmt.close();
      return update_flag;
    } catch (SQLException ex) {
      try {
        if (pstmt != null) pstmt.close();
      } catch (Exception e) {
        USFEnv.getLog().writeCrit("Unable to close statement", this, e);
      }
      USFEnv.getLog().writeCrit("Dinvjrnl: The Updation of Journal Dates failed", this, ex);
    } catch (Exception e) {
      try {
        if (pstmt != null) pstmt.close();
      } catch (Exception ex) {
        USFEnv.getLog().writeCrit("Unable to close statement", this, ex);
      }

      USFEnv.getLog().writeCrit("Unable to close the resultset/prepared statement", this, e);
    }

    return false;
  }
  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");
      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;

      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("<!--%@ page errorPage=\"/error.jsp\" %-->\n");

      response.setHeader("Pragma", "no-cache"); // HTTP 1.0
      response.setDateHeader("Expires", 0);
      response.setHeader("Cache-Control", "no-cache"); // HTTP 1.1

      String _adminid = "";
      String _adminname = "";
      String _admintype = "";
      String _admingroup = "";
      String _approval = "";
      String _adminclass = "";
      String _adminmail = "";

      try {

        _adminid = (String) session.getAttribute("adminid");

        if (_adminid == null || _adminid.length() == 0 || _adminid.equals("null")) {
          response.sendRedirect("/admin/login_first.html");
          return;
        }

        _adminname = (String) session.getAttribute("adminname");
        _admintype = (String) session.getAttribute("admintype");
        _admingroup = (String) session.getAttribute("admingroup");
        _approval = (String) session.getAttribute("approval");
        _adminclass = (String) session.getAttribute("adminclass");
        _adminmail = (String) session.getAttribute("admin_email");
        // session.setMaxInactiveInterval(60*60);

      } catch (Exception e) {
        response.sendRedirect("/admin/login_first.html");
        return;
      }

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

      String password = request.getParameter("password");
      String fromURL = request.getParameter("fromURL");
      String oldPassword = "";

      String sql = "";
      int iCnt = 0;
      boolean isSucceeded = false;
      String strMsg = "";
      Connection conn = null;
      MatrixDataSet matrix = null;
      DataProcess dataProcess = null;
      PreparedStatement pstmt = null;

      String targetUrl = "";

      try {

        if (password.equals("1111")) {
          throw new UserDefinedException(
              "The new password is not acceptable. Change your password.");
        }

        Context ic = new InitialContext();
        DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/scm");
        conn = ds.getConnection();
        matrix = new dbconn.MatrixDataSet();
        dataProcess = new DataProcess();

        sql =
            " select  password " + " from    admin_01t " + " where   adminid = '" + _adminid + "' ";

        iCnt = dataProcess.RetrieveData(sql, matrix, conn);

        if (iCnt > 0) {
          oldPassword = matrix.getRowData(0).getData(0);
        } else {
          throw new UserDefinedException("Can't find User Information.");
        }

        if (password.equals(oldPassword)) {
          throw new UserDefinedException(
              "The new password is not acceptable. Change your password.");
        }

        // update ó¸®...
        int idx = 0;
        conn.setAutoCommit(false);

        sql =
            " update  admin_01t "
                + " set     password = ?, pw_date = sysdate() "
                + " where   adminid = ? ";

        pstmt = conn.prepareStatement(sql);
        pstmt.setString(++idx, password);
        pstmt.setString(++idx, _adminid);

        iCnt = pstmt.executeUpdate();

        if (iCnt != 1) {
          throw new UserDefinedException("Password update failed.");
        }

        conn.commit();
        isSucceeded = true;

      } catch (UserDefinedException ue) {
        try {
          conn.rollback();
        } catch (Exception ex) {
        }

        strMsg = ue.getMessage();
      } catch (Exception e) {
        try {
          conn.rollback();
        } catch (Exception ex) {
        }

        System.out.println("Exception /admin/resetAdminPasswd : " + e.getMessage());
        throw e;
      } finally {
        if (pstmt != null) {
          try {
            pstmt.close();
          } catch (Exception e) {
          }
        }

        if (conn != null) {
          try {
            conn.setAutoCommit(true);
          } catch (Exception e) {
          }
          conn.close();
        }
      }

      // °á°ú ¸Þ½ÃÁö ó¸®
      if (isSucceeded) {
        // where to go?
        if (fromURL.equals("menu")) {
          targetUrl = "";
        } else {
          targetUrl = "/admin/index2.jsp";
        }
        strMsg = "The data are successfully processed.";
      } else {
        strMsg = "The operation failed.\\n" + strMsg;
        targetUrl = "/admin/resetAdminPasswdForm.jsp";
      }

      out.write("\n");
      out.write("<html>\n");
      out.write("<head>\n");
      out.write("<title></title>\n");
      out.write("<link href=\"/common/css/style.css\" rel=\"stylesheet\" type=\"text/css\">\n");
      out.write("</head>\n");
      out.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>\n");
      out.write("<form name=\"form1\" method=\"post\" action=\"");
      out.print(targetUrl);
      out.write("\">\n");
      out.write("<input type='hidden' name='fromURL' value='");
      out.print(fromURL);
      out.write("'>\n");
      out.write("</form>\n");
      out.write("<script language=\"javascript\">\n");
      if (targetUrl.length() > 0) {
        out.write("\n");
        out.write("  alert('");
        out.print(strMsg);
        out.write("');\n");
        out.write("  document.form1.submit();\n");
      }
      out.write("\n");
      out.write("</script>\n");
      out.write("<table width='840' border='0' cellspacing='0' cellpadding='0'><tr><td>\n");
      out.write("\n");
      out.write("<table width='99%' border='0' cellspacing='0' cellpadding='0'>\n");
      out.write("<tr>\n");
      out.write("  <td height='15' colspan='2'></td>\n");
      out.write("</tr>\n");
      out.write("<tr>\n");
      out.write("  <td width='3%'><img src='/img/title_icon.gif'></td>\n");
      out.write("  <td width='*' class='left_title'>Password Change</td>\n");
      out.write("</tr>\n");
      out.write("<tr>\n");
      out.write("  <td width='100%' height='2' colspan='2'><hr width='100%'></td>\n");
      out.write("</tr>\n");
      out.write("<tr>\n");
      out.write("  <td height='10' colspan='2'></td>\n");
      out.write("</tr>\n");
      out.write("</table>\n");
      out.write("\n");
      out.write("<table width='90%' border='0' cellspacing='0' cellpadding='0' align='center'>\n");
      out.write("<tr>\n");
      out.write("  <td width='100%' align='center'><img border=\"0\" src=\"/img/pass.jpg\">\n");
      out.write("    <br><br>\n");
      out.write("    <b>The Password has been changed successfully.</b></td>\n");
      out.write("</tr>\n");
      out.write("</table>\n");

      out.println(CopyRightLogo());

      out.write("\n");
      out.write("</tr></td></table>\n");
      out.write("</body>\n");
      out.write("</html>");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            out.clearBuffer();
          } catch (java.io.IOException e) {
          }
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }