【发布时间】:2018-07-10 14:30:45
【问题描述】:
我是 Java 开发的新手,所以如果我问一些愚蠢的问题,请提前道歉。
我正在尝试从 sql 数据库中检索图像和缩略图。
我从ResultSet 获取BinaryStream 格式的数据,然后将其转换为byte[]。
对于缩略图,它可以正常工作,对于原始图像,我也可以使用 getBinaryStream 方法检索 BinaryStream但是当我将其转换为 byte[] 时,数组仍然为空出于某种原因。
binaryStream = rs.getBinaryStream("image");
thumbBinaryStream = rs.getBinaryStream("thumbnail");
if (binaryStream != null) {
// Tested on following line and I get empty imageBytes
byte[] imageBytes = IOUtils.toByteArray(binaryStream);
thisRecord.put("image", DatatypeConverter.printBase64Binary(imageBytes)); // imageBytes is empty here
}
【问题讨论】:
-
为什么要使用 InputStream 呢?为什么不打电话给ResultSet.getBytes?如
byte[] imageBytes = rs.getBytes("image");? -
我已经尝试了两种方法,但
imageBytes仍然为空,而如果我对thumbBinaryStream执行相同操作并将其转换为字节,我会得到数据。
标签: java sql arrays binarystream ioutils