【问题标题】:How to convert CLOB to image or vice versa?如何将 CLOB 转换为图像,反之亦然?
【发布时间】:2014-06-19 09:14:34
【问题描述】:

在 Oracle 11g 中,我有一个表,其中有一个 CLOB 列,其中包含每一行的图像数据。 我需要将 CLOB 字段转换回图像。我通过谷歌搜索了一下,但我找不到一个可行的例子。 有人可以帮忙吗?

谢谢

【问题讨论】:

  • BLOB 存储图片不是比 CLOB 更好吗?
  • 我当然知道,但是我没有创建数据库,现在我必须处理这个..

标签: java image oracle11g clob


【解决方案1】:

我找到了解决方案。这是我用的

public void convertFromClob(Clob c, File f2) {
    try {
        InputStream inStream = c.getAsciiStream();
        StringWriter sw = new StringWriter();
        IOUtils.copy(inStream, sw);

        // Transfer the data
        byte[] data = Base64.decodeBase64(sw.toString());
        BufferedImage image = ImageIO.read(new ByteArrayInputStream(data));
        ImageIO.write(image, "png", f2);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

您可以直接调用上述方法,将您的 Clob 变量和文件作为参数传递来存储图像。董

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    • 1970-01-01
    相关资源
    最近更新 更多