While switching from deprecated SqlLobValue to SqlBinaryValue we encountered the problem that SqlLobValue fails to pass content given as InputStream if the the size isn't specified accurately, although JDBC could principally process InputStream without a given length, as it is used by DefaultLobHandler$DefaultLobCreator#setBlobAsBinaryStream for content length lower zero.
Therefore SqlBinaryValue should be changed as follows to fix the problem:
/**
* Create a new {@code SqlBinaryValue} for the given content.
* @param stream the content stream
*/
public SqlBinaryValue(InputStream stream) {
this(stream, -1);
}
private void setInputStream(PreparedStatement ps, int paramIndex, int sqlType, InputStream is, long length)
throws SQLException {
if (length >= 0) {
if (sqlType == Types.BLOB) {
ps.setBlob(paramIndex, is, length);
}
else {
ps.setBinaryStream(paramIndex, is, length);
}
return;
}
if (sqlType == Types.BLOB) {
ps.setBlob(paramIndex, is);
}
else {
ps.setBinaryStream(paramIndex, is);
}
}