Skip to content
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

Handle BulkCopy Exceptions #286

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java
Original file line number Diff line number Diff line change
Expand Up @@ -1809,11 +1809,11 @@ private void getSourceMetadata() throws SQLServerException {
}
else if (null != sourceBulkRecord) {
Set<Integer> columnOrdinals = sourceBulkRecord.getColumnOrdinals();
srcColumnCount = columnOrdinals.size();
if (0 == srcColumnCount) {
if (null == columnOrdinals || 0 == columnOrdinals.size()) {
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveColMeta"), null);
}
else {
srcColumnCount = columnOrdinals.size();
Iterator<Integer> columnsIterator = columnOrdinals.iterator();
while (columnsIterator.hasNext()) {
currentColumn = columnsIterator.next();
Expand Down Expand Up @@ -3257,7 +3257,15 @@ private boolean writeBatchData(TDSWriter tdsWriter,
// Copy from a file.
else {
// Get all the column values of the current row.
Object[] rowObjects = sourceBulkRecord.getRowData();
Object[] rowObjects;

try {
rowObjects = sourceBulkRecord.getRowData();
}
catch (Exception ex) {
// if no more data available to retrive
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), ex);
}

for (int i = 0; i < mappingColumnCount; ++i) {
// If the SQLServerBulkCSVRecord does not have metadata for columns, it returns strings in the object array.
Expand Down