日期:2014-05-20 浏览次数:20883 次
public void save(Pet pet) { Connection conn=BaseDao.getConnection(); // String sql="insert into pet(id,master_id,name,type_id,love,health,status,adopt_time) values(pet_seq.nextval,?,?,?,?,?,?,To_Date('2011-10-10','YYYY-MM-DD'));"; String sql="insert into pet(id,master_id,name,type_id,love,health,status,adopt_time) values(55,1,'三三',1,80,90,1,To_Date('2011-10-10','YYYY-MM-DD'));"; PreparedStatement preStmt=null; try { preStmt=conn.prepareStatement(sql); // preStmt.setInt(1, pet.masterId); // preStmt.setString(2, pet.name); // preStmt.setInt(3, pet.typeId); // preStmt.setInt(4, pet.love); // preStmt.setInt(5, pet.health); // preStmt.setInt(6, pet.status); // preStmt.setString(7,pet.adoptTime); preStmt.executeUpdate(); System.out.println("添加记录成功"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ BaseDao.CloasAll(conn, preStmt); } }