示例#1
0
  public boolean addNewSize(Size s) {
    boolean kq = false;
    Connection conn = DBUtils.getConnection();
    PreparedStatement stm = null;
    String query = "INSERT INTO tbl_size(TenSize) VALUES (?)";

    try {
      stm = conn.prepareStatement(query);
      stm.setString(1, s.getTenSize());

      if (stm.executeUpdate() > 0) {
        kq = true;
      }
    } catch (SQLException e) {
      System.err.println(e.getErrorCode() + ":" + e.getMessage());
    } finally {
      DBUtils.closeAll(conn, stm, null);
    }
    return kq;
  }
示例#2
0
  public boolean deleteSize(int maSize) {
    boolean kq = false;
    Connection conn = DBUtils.getConnection();
    PreparedStatement stm = null;
    String query = "DELETE FROM tbl_size WHERE MaSize=?";

    try {
      stm = conn.prepareStatement(query);
      stm.setInt(1, maSize);

      if (stm.executeUpdate() > 0) {
        kq = true;
      }
    } catch (SQLException e) {
      System.err.println(e.getErrorCode() + ":" + e.getMessage());
    } finally {
      DBUtils.closeAll(conn, stm, null);
    }
    return kq;
  }
示例#3
0
  public Size getSizeByTenSize(String tenSize) {
    Size s = null;
    Connection conn = DBUtils.getConnection();
    PreparedStatement stm = null;
    ResultSet rs = null;
    try {
      stm = conn.prepareStatement("SELECT * FROM tbl_size WHERE TenSize=?");
      stm.setString(1, tenSize);
      rs = stm.executeQuery();

      if (rs.next()) {
        s = new Size();
        s.setMaSize(rs.getInt("MaSize"));
        s.setTenSize(rs.getString("TenSize"));
      }
    } catch (SQLException e) {
      System.err.println(e.getErrorCode() + ":" + e.getMessage());
    } finally {
      DBUtils.closeAll(conn, stm, rs);
    }
    return s;
  }
示例#4
0
  public List<Size> getAllSize() {
    List<Size> list = new ArrayList<Size>();
    Connection conn = DBUtils.getConnection();
    PreparedStatement stm = null;
    ResultSet rs = null;
    try {
      stm = conn.prepareStatement("SELECT * FROM tbl_size ORDER BY TenSize");
      rs = stm.executeQuery();

      while (rs.next()) {
        Size s = new Size();
        s.setMaSize(rs.getInt("MaSize"));
        s.setTenSize(rs.getString("TenSize"));
        list.add(s);
      }
    } catch (SQLException e) {
      System.err.println(e.getErrorCode() + ":" + e.getMessage());
    } finally {
      DBUtils.closeAll(conn, stm, rs);
    }
    return list;
  }