我在德比blob列中插入了3個blob(圖像)...。其中一個blob第一次,然後其他條目插入了2個blob ...將blob插入一行。並非所有Blob圖像顯示在jpanel中
blob.getLength()給我合併的3個blob(圖像)的確切字節大小,這表明3個blob已經保存在數據庫中。
然後我試圖得到:
byteArray = blob.getBytes(0,blob.length());
imageIcon=new ImageIcon(byteArray);
或者
inputStream =blob.getBinaryStream();
BufferedImage image=ImageIO.read(inputStream);
imageIcon= new ImageIcon(image);
無論我用,我只得到了第一個BLOB(圖像)顯示在JPanel的... 什麼被阻止其他斑點閱讀並顯示?
private JTextPane createMediaArea() {
String getMediaEditorData = "select mediaEditor from settingsTable where id=6";
Statement stmtBlob;
try {
stmtBlob = settingsConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
try (ResultSet rsMediaEditor = stmtBlob.executeQuery(getMediaEditorData)) {
System.out.println("rsMediaEditor is created ");
while (rsMediaEditor.next()) {
mediaEditorBlob = rsMediaEditor.getBlob("mediaEditor");
if (mediaEditorBlob == null) {
chosenImageIcon = new ImageIcon("./resources.jpg");
scaledChosenImage = chosenImageIcon.getImage().getScaledInstance(100, 100, Image.SCALE_FAST);
scaledImageIcon = new ImageIcon(scaledChosenImage);
mediaArea.insertIcon(scaledImageIcon);
} else {
mediaEditorBlobLength = mediaEditorBlob.length();
System.out.println("mediaEditorBlobLength is : " + mediaEditorBlobLength);
/*1st way is to get the blob array .*/
/*
byte[] mediaEditorByteArray = mediaEditorBlob.getBytes(1L, (int) mediaEditorBlobLength);
int mediaEditorByteArrayLength = mediaEditorByteArray.length;
System.out.println("mediaEditorByteArrayLength is :" + mediaEditorByteArrayLength);
*/
/*2nd way ..use ImageIO*/
InputStream binaryStream = mediaEditorBlob.getBinaryStream();
BufferedImage read = ImageIO.read(binaryStream);
chosenImageIcon= new ImageIcon(read);
scaledChosenImage = chosenImageIcon.getImage().getScaledInstance(100, 100, Image.SCALE_FAST);
scaledImageIcon = new ImageIcon(scaledChosenImage);
mediaArea.insertIcon(scaledImageIcon);
}
}
} catch (IOException ex) {
Logger.getLogger(FrontFace.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("rsMediaEditor closed !");
stmtBlob.close();
System.out.println("stmtBlob closed !");
} catch (SQLException ex) {
Logger.getLogger(FrontFace.class.getName()).log(Level.SEVERE, null, ex);
}
return mediaArea;
}
如果您創建一個ImageIcon,您如何期望繪製3個圖標。你能發佈可運行的短代碼嗎? –
@Jay Smith ....所有3個blob插入並駐留在列的一行中.... inputStream或byteArray是否收集行中可用的所有字節....或部分? – Mohd
您在位置列*行中存儲一個圖像。在1 * 1有一個圖像,但在1 * 2有另一個圖像。相同的列,但不同的行 –