在 AS400 上显示来自 DB2 的 BLOB 内容

Display BLOB contents from DB2 on AS400

我在客户端上编写了一个小型 java 应用程序,它将图像作为 BLOB 插入到 IBM i 上的 table 中。当我查询 table 时,我看到该列已被填充。 我如何将 BLOB 数据显示为图像以确认数据已被 写对了吗?

在 java 应用程序中,我将图像作为 PNG 文件写入 Windows 7 文件夹,我已确认可以使用 Window 照片查看器查看该文件。然后,我在 V7R3 IBM i 上将相同的图像插入我的 table。

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 上的流文件,然后使用照片查看器打开它。