`
danielhjd
  • 浏览: 243291 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

JDBC中insert代码--笔记

    博客分类:
  • JDBC
阅读更多
public static void insertDep(int department_id String department_name, float salary, int location_id){
      (1)调用JDBC的环境构架  
      Connection con=DMmanager.getConnection();
       PreparedStatement pst=null;
       String str="insert into department values(?,?,?,?)";
       pst = con.prepareStatement(str)      
       (2)PreparedStatement类的对象pst的SetIn方法,将insert中的values赋值给pst中的域变量
       pst.setInt(1,department_id);
       pst.setString(2,department_name);
       pst.setFlaot(3,salary);
       pst.setInt(4,location_id)
       (3)执行      
       pst.executeUpdate();
       (4)关闭
       pst.close();
       con.close();

}


PS: I am junior in Java, Look forward to your guys comments and correction,Thanks.
  • 大小: 24.1 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics