检索在MYSQL DB上存储为BLOB的映像 [英] Retrieve an Image stored as BLOB on a MYSQL DB
问题描述
我正在尝试根据驻留在数据库中的信息创建PDF。知道我需要从Java中检索作为BLOB存储在mysql数据库中的TIFF图像。而且我不知道该怎么做。我发现的示例显示了如何检索它并将其保存为文件(但在磁盘上),我需要驻留在内存中。
I'm trying to create a PDF based on the information that resides on a database. Know I need to retrieve a TIFF image that is stored as a BLOB on a mysql database from Java. And I don't know how to do it. The examples I've found shows how to retrieve it and save it as a File (but on disk) and I needed to reside on memory.
表名:IMAGENES_REGISTROS
Table name: IMAGENES_REGISTROS
BLOB字段名称:IMAGEN
BLOB Field name: IMAGEN
任何想法?
推荐答案
在您的 ResultSet
电话:
Blob imageBlob = resultSet.getBlob(yourBlobColumnIndex);
InputStream binaryStream = imageBlob.getBinaryStream(0, imageBlob.length());
或者,您可以致电:
byte[] imageBytes = imageBlob.getBytes(1, (int) imageBlob.length());
正如BalusC在评论中指出的那样,你最好使用:
As BalusC noted in his comment, you'd better use:
InputStream binaryStream = resultSet.getBinaryStream(yourBlobColumnIndex);
然后代码取决于您将如何阅读和嵌入图像。
And then the code depends on how you are going to read and embed the image.
这篇关于检索在MYSQL DB上存储为BLOB的映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!