コード例 #1
0
ファイル: getNewSubstationID.java プロジェクト: worm120/PTS
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    ResultSet rs = null;
    String sid = "000";
    try {

      String sql = "select top 1 Substation_ID from Substation order by Substation_ID desc";
      dataselect ds = new dataselect();
      rs = ds.select(sql);
      if (rs != null) {
        rs.next();
        sid = rs.getString(1);
      }
      rs.close();
      ds.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    // System.out.print(sid);
    int id = Integer.parseInt(sid) + 1;
    out.println(id);
    out.flush();
    out.close();
  }
コード例 #2
0
ファイル: setDevice.java プロジェクト: worm120/PTS
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // System.out.println("ddd");

    request.setCharacterEncoding("gbk");
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    ResultSet rs = null;
    // String Substation_ID=request.getParameter("Substation_ID");
    String Device_ID = request.getParameter("Device_ID");
    String Device_Addr = request.getParameter("Device_Addr");
    String Device_StartH = request.getParameter("Device_StartH");
    String Device_StartL = request.getParameter("Device_StartL");
    String Device_dataL = request.getParameter("Device_dataL");
    String Device_IP = request.getParameter("Device_IP");
    String Device_Port = request.getParameter("Device_Port");
    String Device_Feature = request.getParameter("Device_Feature");

    try {
      dataselect ds = new dataselect();
      String is_exiString = "select count(*) from DeviceSet where Device_ID='" + Device_ID + "'";
      rs = ds.select(is_exiString);
      int tem = -1;
      if (rs != null) {
        while (rs.next()) {
          tem = rs.getInt(1);
        }
      }

      String sql = "";

      if (tem > 0) {
        sql =
            "update  DeviceSet set Device_Addr='"
                + Device_Addr
                + "',Device_Feature='"
                + Device_Feature
                + "',Device_StartH='"
                + Device_StartH
                + "',Device_StartL='"
                + Device_StartL
                + "',Device_dataL='"
                + Device_dataL
                + "',Device_IP='"
                + Device_IP
                + "',Device_Port='"
                + Device_Port
                + "' where Device_ID='"
                + Device_ID
                + "'";

      } else {
        sql =
            "insert into DeviceSet(Device_ID,Device_Addr,Device_Feature,Device_StartH,Device_StartL,Device_dataL,Device_IP,Device_Port) values('"
                + Device_ID
                + "','"
                + Device_Addr
                + "','"
                + Device_Feature
                + "','"
                + Device_StartH
                + "','"
                + Device_StartL
                + "','"
                + Device_dataL
                + "','"
                + Device_IP
                + "','"
                + Device_Port
                + "')";
      }
      // System.out.println(sql);
      int i = ds.update(sql);
      rs.close();
      ds.close();

      if (i > 0) {
        out.print("success");
      } else {
        out.print("fail");
      }

    } catch (Exception ex) {
      ex.printStackTrace();
    }
    out.flush();
    out.close();
  }