首页 > 数据库技术 > 详细

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

时间:2017-12-13 13:15:58      阅读:226      评论:0      收藏:0      [点我收藏+]
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给数据库增加和修改数据代码

原文:http://www.cnblogs.com/wangyufei123/p/8032042.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!