在AS400上显示DB2上的BLOB内容

问题描述 投票:1回答:1

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

在java应用程序中,我将图像写入Windows 7文件夹作为PNG文件,我已经确认可以使用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个回答
2
投票

您不是将图像存储为base64,而是将其存储为二进制文件,因此base64-to-image转换器无法提供帮助。

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

© www.soinside.com 2019 - 2024. All rights reserved.