1 pièce(s) jointe(s)
Afficher plusieurs images d'une BDD MySql
Bonjour,
En JEE, j'arrive à afficher des images dans la 1ère colonne, mais pas dans les autres. Je ne comprends pas trop pourquoi ! (J'ai un profil JUNIOR en dév).
Je vais mettre le code de ma servlet ainsi que de ma classe DaoImpl.
Servlet :
Code:
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
| if (path.equals("/image")) {
String uri = request.getRequestURI();
int index = uri.lastIndexOf("/");
String imageName = uri.substring(index + 1, uri.length());
try {
Blob imageEnBdds = metier.affImg(imageName); /* La méthode pr l'affichage des images est de type Blob */
if (imageEnBdds.length() >= 1) {
byte[] imageData = imageEnBdds.getBytes(1, (int) imageEnBdds.length());
response.setContentType("image/png");
OutputStream o = response.getOutputStream();
o.write(imageData);
o.flush();
o.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(imageName);
} |
DaoImpl :
Code:
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
| public java.sql.Blob affImg(String img1) {
Connection connection = ConnexionBDD.getConnection();
java.sql.Blob blob = null; /* A la base qu'une ligne */
try {
PreparedStatement ps = (PreparedStatement) connection.prepareStatement(
"SELECT img1,img2,img3,img4,img5 FROM bsolutionwithimg WHERE bsolutionwithimg.bsolution1 LIKE ? ");
ps.setString(1, img1);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
// ORM
blob = rs.getBlob("img1");
/*
* blob2 = rs.getBlob("img2"); blob3 = rs.getBlob("img3"); blob4 =
* rs.getBlob("img4"); blob5 = rs.getBlob("img5");
*/
/*
* Il me retourne qu'une seule image -> img1, je crée un blob total ?!
* blobGeneral = rs .getBlob("img1" + blob + "img2" + blob2 + "img3" + blob3 +
* "img4" + blob4 + "img5" + blob5);
*/
}
} catch (Exception e) {
e.printStackTrace();
}
return blob;
// return blobGeneral; |
J'ai mis une capture d'ecran pour que vous ayez un visuel
Pièce jointe 384799
Auriez-vous une idéé ?