Inserting byte[] array as blob in Oracle Database getting ORA-01460: unimplemented or unreasonable conversion requested

Deadly 提交于 2019-12-31 02:30:30

问题


I have a java stored procedure that I am trying to insert a byte[] array into an oracle blob field in a table.

I create a prepared statement as follows but it will randomly fail when I execute the prepared statement. I have narrowed down that the issue is coming from the pstmt.setBytes(4,content). The error I get is:

ORA-01460: unimplemented or unreasonable conversion requested.

private static void insertFile(Connection connOracle, int zipFileId, byte[] data, String filepath, String filename ) throws SQLException {

try {
    String QUERY = "INSERT INTO files(file_id, zip_file_id, filename, file_path, content) VALUES(SEQ_FILE_ID.nextval,?,?,?,?)";

    PreparedStatement pstmt = connOracle.prepareStatement(QUERY);

    pstmt.setInt(1,zipFileId);
    pstmt.setString(2, filename);
    pstmt.setString(3, filepath);
    pstmt.setBytes(4, data);

    System.out.println("INSERTING file_id " + filepath + ", " + filename + " INTO DATABASE");

    pstmt.execute();
    pstmt.close();
}
catch (SQLException e) {
    throw new SQLException(e.getMessage());  
}

回答1:


If I recall correctly the Oracle JDBC drivers (at least older ones - you didn't tell us which version you are using) don't support setBytes() (or getBytes()).

In my experience, using setBinaryStream() is much more reliable and stable:

InputStream in = new ByteArrayInputStream(data);
pstmt.setBinarySream(4, in, data.length);



回答2:


try with the below code, this should work for you :-

Blob blobValue = new SerialBlob(data);
pstmt.setBlob(4, blobValue);


来源:https://stackoverflow.com/questions/7794197/inserting-byte-array-as-blob-in-oracle-database-getting-ora-01460-unimplement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!