Exemplo n.º 1
0
  public boolean addtyp(TypeBean tb) {
    boolean flag = false;
    DConnection d = new DConnection();
    Connection con = null;

    try {
      con = d.getConnection();

      PreparedStatement pstmt = con.prepareStatement("insert into types values(?,?,?,?)");
      pstmt.setInt(1, tb.getT_id());
      pstmt.setString(2, tb.getT_node());
      pstmt.setInt(3, tb.getDownlink());
      pstmt.setInt(4, tb.getUplink());
      int i = pstmt.executeUpdate();
      System.out.println(i);
      if (i == 1) {
        flag = true;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    /*
     * finally(){ con.close();
     *
     * }
     */
    return flag;
  }
Exemplo n.º 2
0
  public TypeList getTypeData() {
    DConnection d = new DConnection();
    TypeList list = new TypeList();
    try {
      Connection con = d.getConnection();
      TypeBean type = null;
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery("select * from types");
      while (rs.next()) {
        type = new TypeBean();
        type.setT_id(rs.getInt(1));
        type.setT_node(rs.getString(2));
        type.setDownlink(rs.getInt(3));
        type.setUplink(rs.getInt(4));
        list.add(type);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    return list;
  }
Exemplo n.º 3
0
  public boolean UpdateType(TypeBean tb) {

    DConnection d = new DConnection();
    Connection con = null;
    boolean status = false;
    int i = 0;
    try {
      con = d.getConnection();
      PreparedStatement pstmt =
          con.prepareStatement("update types set t_node=?,downlinks=?,uplinks=? where T_id=?");
      pstmt.setString(1, tb.getT_node());
      pstmt.setInt(2, tb.getDownlink());
      pstmt.setInt(3, tb.getUplink());
      pstmt.setInt(4, tb.getT_id());
      i = pstmt.executeUpdate();
      System.out.println(i);
      if (i == 1) {
        status = true;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return status;
  }
Exemplo n.º 4
0
  public TypeBean ViewType(int tid) {

    DConnection d = new DConnection();
    Connection con = null;

    TypeBean tb = new TypeBean();
    try {
      con = d.getConnection();
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery("Select * from types where T_id=" + tid);
      if (rs != null)
        while (rs.next()) {
          tb.setT_id(rs.getInt(1));
          tb.setT_node(rs.getString(2));
          tb.setDownlink(rs.getInt(3));
          tb.setUplink(rs.getInt(4));
        }
      else tb = null;

    } catch (Exception e) {
      e.printStackTrace();
    }
    return tb;
  }