1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
/**Enregistrement dans la table des produits*/
public void sauveIMG_PROD(String front, String back, String right,
String left, String iconFront, String iconBack, String iconRight,
String iconLeft, String nom) throws SQLException,
FileNotFoundException, IOException {
// TODO Auto-generated method stub
File imageFront = new File(front);
File imageBack = new File(back);
File imageRight = new File(right);
File imageLeft = new File(left);
File icoFront = new File(iconFront);
File icoBack = new File(iconBack);
File icoRight = new File(iconRight);
File icoLeft = new File(iconLeft);
FileInputStream fisFront = new FileInputStream(imageFront);
FileInputStream fisBack = new FileInputStream(imageBack);
FileInputStream fisRight = new FileInputStream(imageRight);
FileInputStream fisLeft = new FileInputStream(imageLeft);
FileInputStream fisIcoFront = new FileInputStream(icoFront);
FileInputStream fisIcoBack = new FileInputStream(icoBack);
FileInputStream fisIcoRight = new FileInputStream(icoRight);
FileInputStream fisIcoLeft = new FileInputStream(icoLeft);
try {
conn = initialiserConnexion();
String sql = "insert into produit (nom, front, back, rights, lefts, frontc, backc, rightsc, leftsc) values (?,?,?,?,?,?,?,?,?)";
PreparedStatement ps = conn.prepareStatement(sql);
try {
ps.setString(1, nom);
ps.setBinaryStream(2, fisFront, (int) imageFront.length());
ps.setBinaryStream(3, fisBack, (int) imageFront.length());
ps.setBinaryStream(4, fisRight, (int) imageFront.length());
ps.setBinaryStream(5, fisLeft, (int) imageFront.length());
ps.setBinaryStream(6, fisIcoFront, (int) icoFront.length());
ps.setBinaryStream(7, fisIcoBack, (int) icoBack.length());
ps.setBinaryStream(8, fisIcoRight, (int) icoRight.length());
ps.setBinaryStream(9, fisIcoLeft, (int) icoLeft.length());
ps.executeUpdate();
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
arret("Enregistrement produit échoué");
} finally {
ps.close();
}
} finally {
fisFront.close();
fisBack.close();
fisRight.close();
fisLeft.close();
fisIcoFront.close();
fisIcoBack.close();
fisIcoRight.close();
fisIcoLeft.close();
} |
Partager