JDBC中insert代码--笔记

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.

你可能感兴趣的:(jdbc)