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

Posted 你可别玩了

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用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;

 

以上是关于用JAVA给数据库增加和修改数据代码的主要内容,如果未能解决你的问题,请参考以下文章