-
Notifications
You must be signed in to change notification settings - Fork 448
Add support for InputStream data type using setBinaryStream() for bulk copy for batch insert API #2826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ulk copy for batch insert API
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2826 +/- ##
============================================
+ Coverage 52.26% 52.30% +0.04%
- Complexity 4152 4160 +8
============================================
Files 149 149
Lines 34378 34378
Branches 5734 5734
============================================
+ Hits 17966 17980 +14
+ Misses 13918 13905 -13
+ Partials 2494 2493 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Ananya2
approved these changes
Oct 31, 2025
machavan
approved these changes
Nov 3, 2025
divang
approved these changes
Nov 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
GitHub issue : setBinaryStream() fails with Bulk Copy for Batch Insert in JDBC Driver 13.2.0
When using Bulk Copy for Batch Insert with setUseBulkCopyForBatchInsert(true) and inserting data into a [VARBINARY(MAX) column using PreparedStatement.setBinaryStream(), the insert operation fails with the following error:
Root cause
The issue lies in the convertValue method within SQLServerBulkBatchInsertRecord. The method correctly handles byte[] arrays for binary data types but does not handle InputStream objects.
When setBinaryStream() is used, the InputStream object falls into the else clause, causing data.toString() to return the Java object string representation (e.g., [java.io.ByteArrayInputStream@4e25154f]), which the driver later tries to interpret as hex data, resulting in the "invalid hex format" exception.
Fix
Modified the condition in the convertValue method to handle both byte[] and InputStream objects as binary data
Testing
Added comprehensive test case testBulkCopyBatchInsertForInputStreamData in BatchExecutionWithBulkCopyTest that: