请教高手帮忙啊!!!!!!急求关于数据访问DAO的问题
public void modifyStatus(String userName, String status, Date employeeTo,
Connection conn) throws MyException {
String sql = "update Employee set Status=?,EmployeeTo=? where UserName=?";
try {
ps = conn.prepareStatement(sql);
ps.setString(1, status);
ps.setDate(2, employeeTo);
ps.setString(3, userName);
ps.execute();
} catch (
SQLException e) {
logger.error(e.getMessage());
throw new MyException("修改员工状态失败", e);
} finally {
DBUtil.close(ps);
}
}此方法,如何改进当增加字段时不用再单独写一个方法,求教高手帮忙啊!!!!!!!
------解决方案--------------------没办法吧,增加字段,就得增加方法传入的参数,直接方法复制一份,
重载,该的地方不多,
public void modifyStatus(String userName, String status, Date employeeTo,String age,
Connection conn) throws MyException {
String sql = "update Employee set Status=?,EmployeeTo=?,Age=? where UserName=?";
try {
ps = conn.prepareStatement(sql);
ps.setString(1, status);
ps.setDate(2, employeeTo);
ps.setString(3, userName);
ps.setString(4, age);
ps.execute();
} catch (SQLException e) {
logger.error(e.getMessage());
throw new MyException("修改员工状态失败", e);
} finally {
DBUtil.close(ps);
}
------解决方案--------------------可以使用两个sql语句,进行判断,看要调用哪个sql语句(主要根据id主键进行判断)