Skip to content

Commit 3046fdd

Browse files
committed
DefaultLobCreator's streamAsLob mode supports JDBC 4.0 setBlob/Clob variants without length parameter as well
Issue: SPR-12265
1 parent d65db65 commit 3046fdd

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/DefaultLobHandler.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,12 @@ public void setBlobAsBinaryStream(
255255

256256
if (streamAsLob) {
257257
if (binaryStream != null) {
258-
ps.setBlob(paramIndex, binaryStream, contentLength);
258+
if (contentLength >= 0) {
259+
ps.setBlob(paramIndex, binaryStream, contentLength);
260+
}
261+
else {
262+
ps.setBlob(paramIndex, binaryStream);
263+
}
259264
}
260265
else {
261266
ps.setBlob(paramIndex, (Blob) null);
@@ -318,7 +323,13 @@ public void setClobAsAsciiStream(
318323
if (streamAsLob) {
319324
if (asciiStream != null) {
320325
try {
321-
ps.setClob(paramIndex, new InputStreamReader(asciiStream, "US-ASCII"), contentLength);
326+
Reader reader = new InputStreamReader(asciiStream, "US-ASCII");
327+
if (contentLength >= 0) {
328+
ps.setClob(paramIndex, reader, contentLength);
329+
}
330+
else {
331+
ps.setClob(paramIndex, reader);
332+
}
322333
}
323334
catch (UnsupportedEncodingException ex) {
324335
throw new SQLException("US-ASCII encoding not supported: " + ex);
@@ -355,7 +366,12 @@ public void setClobAsCharacterStream(
355366

356367
if (streamAsLob) {
357368
if (characterStream != null) {
358-
ps.setClob(paramIndex, characterStream, contentLength);
369+
if (contentLength >= 0) {
370+
ps.setClob(paramIndex, characterStream, contentLength);
371+
}
372+
else {
373+
ps.setClob(paramIndex, characterStream);
374+
}
359375
}
360376
else {
361377
ps.setClob(paramIndex, (Clob) null);

0 commit comments

Comments
 (0)