在 MYSQL 数据库上检索存储为 BLOB 的图像 [英] Retrieve an Image stored as BLOB on a MYSQL DB

查看:36
本文介绍了在 MYSQL 数据库上检索存储为 BLOB 的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据驻留在数据库中的信息创建 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 数据库上检索存储为 BLOB 的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆