【问题标题】:Store byte[] in BLOB Oracle在 BLOB Oracle 中存储 byte[]
【发布时间】:2013-12-09 20:27:37
【问题描述】:

我正在执行以下操作以将其插入 BLOB Oracle 11g。

图像以 Base64 编码 存储在从 XML 中提取的字符串中。

String str = "xyz...."
byte[] bytes = str.getBytes();
InputStream is = new ByteArrayInputStream(bytes);

PreparedStatement prepStmt = dbCon.prepareStatement("insert into Table(INDEX,RESPONSE_IMAGE) values(?,?);
prepStmt.setString(1, action.getIndex());
prepStmt.setBinaryStream(2, is, str.length());

我认为问题是图像的字节长度,因为当我得到字符串的长度()时,它大约是 200,000 字节

当我对字符串执行 subString(3000) 时,它很容易保存在 BLOB 列中

那么问题到底出在哪里??

  1. 图片长度是否过长?
  2. 或者我应该选择 Oracle 的任何其他数据类型?

我读到 BLOB 最多可以保存 4GB 数据,那为什么不是我的呢??

【问题讨论】:

    标签: java oracle jdbc oracle11g


    【解决方案1】:

    在 JDBC 中使用 Blob 的 Oracle 教程是 here

    相关部分:

    Clob myClob = this.con.createClob();
    Writer clobWriter = myClob.setCharacterStream(1);
    

    与:

    添加和检索 BLOB SQL 对象类似于添加和检索 CLOB SQL 对象。使用 Blob.setBinaryStream 方法检索 OutputStream 对象以写入 Blob Java 对象(调用该方法)表示的 BLOB SQL 值。

    【讨论】:

    • 按照你的方式,我在 Clob myClob = this.con.createClob(); 上得到以下异常; java.lang.AbstractMethodError at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.createClob(DelegatingConnection.java:582)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-24
    • 2012-01-14
    • 2016-12-07
    • 2010-11-06
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    相关资源
    最近更新 更多