ขอคำแนะนำเกี่ยวกับการ get รูปภาพจาก database ด้วย JSP ค่ะ
Blob image = null;
byte[] imgData = null;
try {
ResultSet rs = stmt.executeQuery("Select pic from pictures");
if (rs != null)
{
while(rs.next()){
image = rs.getBlob(1);
imgData = image.getBytes(1, (int) image.length());
}
} else {
System.out.println("Icon not found");
return;
}
response.setContentType("image/jpg");
OutputStream os = response.getOutputStream();
os.write(imgData);
os.flush();
os.close();
}catch ....
จาก code ข้างต้น สามารถ Select รูปออกมาได้เพียงแค่ รูปเดียว ทั้งที่ความเป็นจริงแล้ว
ใน table มีข้อมูลอีกเป็นสิบรูป อยากทราบว่าจะมีวิธี get ค่าอย่างไรได้อีกคะ
ควร get ออกมาเป็น array หรือว่ามีวิธีอื่นๆได้อีกคะ
ขอบคุณค่ะ
ขอคำแนะนำเกี่ยวกับ getBlob JSP ค่ะ
Blob image = null;
byte[] imgData = null;
try {
ResultSet rs = stmt.executeQuery("Select pic from pictures");
if (rs != null)
{
while(rs.next()){
image = rs.getBlob(1);
imgData = image.getBytes(1, (int) image.length());
}
} else {
System.out.println("Icon not found");
return;
}
response.setContentType("image/jpg");
OutputStream os = response.getOutputStream();
os.write(imgData);
os.flush();
os.close();
}catch ....
จาก code ข้างต้น สามารถ Select รูปออกมาได้เพียงแค่ รูปเดียว ทั้งที่ความเป็นจริงแล้ว
ใน table มีข้อมูลอีกเป็นสิบรูป อยากทราบว่าจะมีวิธี get ค่าอย่างไรได้อีกคะ
ควร get ออกมาเป็น array หรือว่ามีวิธีอื่นๆได้อีกคะ
ขอบคุณค่ะ