我在客户端上编写了一个小型 Java 应用程序,它将图像作为 BLOB 插入到 IBM i 上的表中。当我查询表时,我看到该列已被填充。 如何将 BLOB 数据显示为图像以确认数据已被 写对了吗?
在 java 应用程序中,我将图像作为 PNG 文件写入 Windows 7 文件夹,我已确认可以使用 Window Photo Viewer 查看该图像。然后,我将相同的图像插入到 V7R3 IBM i 上的表中。
Blob blob = conn.createBlob();
try {
os = new ByteArrayOutputStream();
ObjectOutputStream oos;
oos = new ObjectOutputStream(blob.setBinaryStream(1));
oos.writeObject(outputfile);
oos.close();
// Write the image as a BLOB to prfruncap
queryStr = "INSERT INTO prfdta.prfruncap (rcrun, rcseq, rcimage)"
+ " VALUES(?,?,?)";
pstmt1 = conn.prepareStatement(queryStr);
pstmt1.setInt(1,run);
pstmt1.setInt(2, sequence);
pstmt1.setBlob(3, blob);
pstmt1.executeUpdate();
} catch (SQLException seRs) {
seRs.printStackTrace();
throw seRs;
} catch (IOException e) {
e.printStackTrace();
}
当我查询数据时,我确实看到该列确实包含数据。我希望可以将数据粘贴到在线转换器中,例如( https://codebeautify.org/base64-to-image-converter ),但我无法显示图像。 我可以将 BLOB 数据作为图像查看以确认其写入正确吗?
最佳答案
您没有将图像存储为 base64,而是将其存储为二进制,因此 base64 到图像转换器不会有帮助。
将字节写回 PC 甚至 IFS 上的流文件,然后使用照片查看器打开它。
关于java - 在 AS400 上显示 DB2 中的 BLOB 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55784890/