How to view image from blob column in Oracle using JasperReports?

I tried to define an image element in the report layout and set the type to java.io.Inputstream, but this does not work, also I tried to set java.awt.Image and it does not work, the exception I get

java.lang.ClassCastException: oracle.sql.BLOB cannot be cast to java.awt.Image 

or

 java.lang.ClassCastException: oracle.sql.BLOB cannot be cast to java.io.InputStream 

I also tried Google, but the results are what I'm doing right now.

Thank you for your help.

+4
source share
2 answers

Not seeing how you call blob to embed the image in your report code ...

For instance:

 javax.imageio.ImageIO.read( blob.getBinaryStream() ) 

This will return an instance of BufferedImage , which is a subclass of java.awt.Image and should be a suitable object to be inserted into the report.

The blob variable shown in the example will need to use the corresponding variable from the report (which represents the data from the desired column).

See also:

+2
source
 InputStream is = new ByteArrayInputStream((byte[]) yourBlobData); myImage = new DefaultStreamedContent(is, "image/png"); 

on the jsf page;

 <p:graphicImage value="#{controller.myImage}" style="width:200px;width:500px" /> 
0
source

Source: https://habr.com/ru/post/1432381/


All Articles