public boolean updateSize(Size s) { boolean kq = false; Connection conn = DBUtils.getConnection(); PreparedStatement stm = null; String query = "UPDATE tbl_size SET TenSize=? WHERE MaSize=?"; try { stm = conn.prepareStatement(query); stm.setString(1, s.getTenSize()); stm.setInt(2, s.getMaSize()); if (stm.executeUpdate() > 0) { kq = true; } } catch (SQLException e) { System.err.println(e.getErrorCode() + ":" + e.getMessage()); } finally { DBUtils.closeAll(conn, stm, null); } return kq; }
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; }
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; }
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; }