【问题标题】:Display BLOB contents from DB2 on AS400在 AS400 上显示来自 DB2 的 BLOB 内容
【发布时间】:2019-04-21 17:09:00
【问题描述】:

我在客户端编写了一个小型 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 数据作为图像查看以确认其写入正确吗?

【问题讨论】:

    标签: java ibm-midrange db2-400


    【解决方案1】:

    您不是将图像存储为 base64,而是将其存储为二进制文件,因此 base64 到图像的转换器将无济于事。

    将字节写回流文件,在 PC 甚至 IFS 上,然后使用照片查看器打开它。

    【讨论】:

      猜你喜欢
      • 2018-08-03
      • 2016-11-18
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2018-03-05
      • 2020-02-20
      相关资源
      最近更新 更多