在Oracle数据库中将byte []数组作为blob插入ORA-01460:请求未实现或不合理的转换 [英] Inserting byte[] array as blob in Oracle Database getting ORA-01460: unimplemented or unreasonable conversion requested

查看:97
本文介绍了在Oracle数据库中将byte []数组作为blob插入ORA-01460:请求未实现或不合理的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个java存储过程,我试图将byte []数组插入表中的oracle blob字段。

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

我按如下方式创建一个预准备语句,但是当我执行预准备语句时它会随机失败。我已经缩小了问题来自pstmt.setBytes(4,content)。我得到的错误是:

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:请求未实现或不合理的转换。

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());  
}


推荐答案

如果我没记错Oracle JDBC驱动程序(至少是较旧的驱动程序 - 您没有告诉我们您使用的是哪个版本)不支持 setBytes()(或 getBytes( ))。

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()).

根据我的经验,使用 setBinaryStream()更加可靠并且稳定:

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

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

这篇关于在Oracle数据库中将byte []数组作为blob插入ORA-01460:请求未实现或不合理的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆