我们要插入/修改一个有blog类型的表,使用了如下的代码:byte[] value =...
PreparedStatement stmt=...if (value == null) {
    stmt.setNull( parameterIndex, Types.BLOB );
}
else {
   stmt.setBinaryStream( parameterIndex, new ByteArrayInputStream(value), value.length );
}
如果value的长度小于4000,工作正常,但是value的长度超过4000的时候,就会报如下的错误:java.sql.SQLException: ORA-01460: 转换请求无法实现或不合理
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
        at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
        at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
        at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
        at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:109
3)
        at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.ja

解决方案 »

  1.   

    BLOG最大为4GB的
    你检查一下
      

  2.   

    不是,blob字段用这种方式最大就可以插入4000。要先插入一个空的,再以流的形式写进去才行。
    conn.setAutoCommit(false);         
            String sqlInsert = "INSERT INTO FISHBONE_DIAGRAM ( FISHBONE_DIAGRAM_ID,TIPS_ID, DIAGRAM_RAWDATA) VALUES (100, 2, empty_blob() )";
    stmt.executeUpdate(sqlInsert);

    ResultSet rset=stmt.executeQuery("SELECT DIAGRAM_RAWDATA FROM FISHBONE_DIAGRAM where FISHBONE_DIAGRAM_ID=100 for update");
    byte[] b = new byte[3];
    b[0]='a';
    b[1]='b';
    b[2]='c';
    if (rset.next()) {
     oracle.sql.BLOB blob = (oracle.sql.BLOB) rset.getBlob("DIAGRAM_RAWDATA");
     OutputStream out = blob.getBinaryOutputStream();
                     out.write(b);
                     out.flush();
                     out.close();

    }
    conn.commit();