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


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;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM