2015-06-10 28 views

回答

3

一些代碼塊,如果能夠幫助你:

ResultSet rs = stmt.executeQuery(<Your Query SQL>); 
java.sql.Blob blob = rs.getBlob(column); 
InputStream in = blob.getBinaryStream(); 
BufferedImage image = ImageIO.read(in); 

在JLabel的,你應該使用的BufferedImage。

0

你可以試試這個...

// Fetch BLOB from DB 
    Blob blb = stmt.executeQuery(...).getBlob("blobColumn"); 

    // Read BLOB into byte-Array 
    byte[] imagebytes = blb.getBytes(0, blb.length()); 

    // convert byte-Array into Buffered Image (Subclass of Image) 
    BufferedImage theImage=ImageIO.read(new ByteArrayInputStream(imagebytes)); 

處理異常和真正的代碼緊密流!

+0

感謝您的幫助!但我不明白與閱讀BLOB到字節數組的行。你可以發佈全線嗎?謝謝 – user4473495

+0

增加了字節數組訪問...雖然我喜歡'代碼熊貓的建議,因爲它看起來更清晰一些,如果它是一個非常大的圖像,它可能會更好地編碼它的方式 –

相關問題