用JAVA给数据库增加和修改数据代码

时间:2021-11-18 00:38:46
public  class DeptDao{
    public int a    dd(Connection conn,Dept dept)  throws Exception{
         String sql="insert into dept values(?,?,?,)";
         PreparedStatement pst=conn.prepareStatement(sql);
         pst.setInt(1,dept.getDeptno());
         pst.setString(2,dept.getDname());
         pst.setString(3,dept.getLoc());
         return pst.executeUpdate();
    }
public int modify(Connection conn,Dept dept) throws Exception{
         String sql ="Update dept set dname=?,loc=?where deptno=?;
         PrepareStstement pst=conn.prepareStatement(sql);
        pst.setString(1,dept.getDname());
        pst.setString(2,dept.getLoc());
        pst.setInt(3,dept.getDeptno());
        int i=pst.executeUpdate();
        return i;