![](/img/trans.png)
[英]store image in oracle database— error— ORA-01460: unimplemented or unreasonable conversion requested
[英]Inserting byte[] array as blob in Oracle Database getting ORA-01460: unimplemented or unreasonable conversion requested
我有一个java存储过程,我试图将byte []数组插入表中的oracle blob字段。
我创建了一个如下的预准备语句,但是当我执行预准备语句时它会随机失败。 我已经缩小了问题来自pstmt.setBytes(4,content)。 我得到的错误是:
ORA-01460:请求未实现或不合理的转换。
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()
)。
根据我的经验,使用setBinaryStream()
更加可靠和稳定:
InputStream in = new ByteArrayInputStream(data);
pstmt.setBinarySream(4, in, data.length);
尝试下面的代码,这应该适合你: -
Blob blobValue = new SerialBlob(data);
pstmt.setBlob(4, blobValue);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.