如何使用JasperReports查看Oracle中blob列的图像?

如何使用JasperReports查看Oracle中blob列的图像?

问题描述:

我尝试在报表布局中定义一个图像元素,并将类型设置为java.io.Inputstream,但这不起作用,我也尝试设置为java.awt.Image并且都不起作用,我得到的例外情况是

I tried defining an image element in the report layout and setting type to java.io.Inputstream but that doesn't work, also I tried setting to java.awt.Image and neither works, the exception that I'm getting is

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

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

另外我也是尝试谷歌,但结果是我现在正在做的。

Also I tried to google but the results are that what I'm doing right now.

感谢您的帮助。

没有看到你如何调用blob将图像嵌入到报告代码中...

Without seeing how you're calling the blob to embed the image within your report code...


  1. 使用 blob.getBinaryStream()

  2. 使用 javax.imageio.ImageIO.read(InputStream)

  1. Use blob.getBinaryStream().
  2. Convert the stream using javax.imageio.ImageIO.read( InputStream ).

例如:

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

这将返回 BufferedImage ,其子类为 java.awt.Image ,应该是嵌入报告的合适对象。

This will return an instance of BufferedImage, which subclasses java.awt.Image, and should be a suitable object to embed in the report.

显示的 blob 变量该示例必须使用报表中的相应变量(表示所需列中的数据)。

The blob variable shown in the example will have to use the appropriate variable from the report (that represents the data from the desired column).

另请参阅:

  • https://forums.oracle.com/forums/thread.jspa?threadID=2081381