e.setManager(rs.getInt("mgr"));
e.setSal(rs.getFloat("sal"));
e.setComm(rs.getFloat("comm"));
Date d = rs.getDate("hiredate");
java.util.Date dd = new java.util.Date(d.getTime());
String str = dd.getYear() + 1900 + "-" + (dd.getMonth() + 1) + "-" + dd.getDate();
e.setHiredate(str);
e.setDeptno(rs.getInt("deptno"));
}
// 7. 关闭
rs.close();
ps.close();
conn.close();
return e;
}
public void deleteById(int id) throws ClassNotFoundException, SQLException {
Connection conn = DBUtil.getConnection();
String sql = "delete from emp where empno=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, id);
ps.executeUpdate();
// 7. 关闭
ps.close();
conn.close();
}
public void add(Emp e) throws ClassNotFoundException, SQLException {
Connection conn = DBUtil.getConnection();
String sql = "insert into emp ("
+ "empno, "
+ // 员工编号
"ename, "
+ "job, "
+ "mgr, "
+ "sal, "
+ "comm, "
+ "hiredate, "
+ "deptno) "
+ "values (SEQ_EMP_EMPNO.nextval, ?, ?, ?, ?, ?, to_date(?, 'YYYY-MM-
DD'), ?)";
PreparedStatement ps = conn.prepareStatement(sql);