1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public void ajoute(Machine machine) throws LectureBDDException {
DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
PreparedStatement pst=null;
try {
pst = this
.getConnection()
.prepareStatement(
"Insert Into MACHINE (idMarque,modele,numSerie,numAfpa,nomMachine,adresseIP,dateAchat,finGarantie,idSalle,idParc) Values(?,?,?,?,?,?,?,?,?,?)",
new String[] { "idMachine" });
pst.setInt(1, machine.getMarque().getIdMarque());
pst.setString(2, machine.getModele());
pst.setString(3, machine.getNumSerie());
pst.setString(4, machine.getNumAfpa());
pst.setString(5, machine.getNomMachine());
pst.setString(6, machine.getAdresseIp());
pst.setNString(7, format.format(machine.getDateAchat().getTime()));
pst.setNString(8, format.format(machine.getDateFinGarantie().getTime()));
pst.setInt(9, machine.getSalle().getIdSalle());
pst.setInt(10, machine.getIdParc());
pst.executeUpdate();
machine.setIdMachine(getAutoIncrementId(pst));
log.log(Level.INFO, "machine ajoutée:" + machine.toString());
pst.close(); |
Partager