Skip to content

SqlBinaryValue and SqlCharacterValue should support InputStream content with undetermined length #36219

@meincs

Description

@meincs

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

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions