Driver version
12.10.0.jre11
SQL Server version
Microsoft SQL Server 2019 (RTM-CU32-GDR) (KB5065222) - 15.0.4445.1 (X64) Aug 13 2025 11:07:18 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro 10.0 (Build 19045: )
Client Operating System
Ubuntu 24.04.3 LTS
JAVA/JVM version
Java 21 (openjdk 21.0.8 2025-07-15)
Problem description
Bulk insert does not handle string containing ".
I call the MsSqlServer:doBulkInsert with these parameters:
bulkInsertBase = {BulkInsertBase@12886}
rowCount = 17562
ignoreCount = 0
fieldsTerminatedBy = "\t"
value = {byte[1]@12923} [9]
coder = 0
hash = 9
hashIsZero = false
tableName = "syncphrase"
forceEmpty = false
recreateTable = true
keepIdentity = false
tableLock = false
fields = {Arrays$ArrayList@12911} size = 5
0 = {StringField@12914} "Name: namespace, DbName: namespace, Pos: 7, Type: java.lang.String, Database type: java.lang.String, Allow null: no, Size: 500, Truncated: false, Fulltext indexed: false, Default value: , Collation: default"
1 = {StringField@12915} "Name: key, DbName: key_, Pos: 6, Type: java.lang.String, Database type: java.lang.String, Allow null: no, Size: 500, Truncated: false, Fulltext indexed: false, Default value: , Collation: default"
2 = {StringField@12916} "Name: phrase_en, DbName: phrase_en, Pos: 4, Type: java.lang.String, Database type: java.lang.String, Allow null: no, Size: 2000, Truncated: false, Fulltext indexed: false, Default value: , Collation: default"
3 = {StringField@12917} "Name: taskId, DbName: taskId, Pos: 10, Type: java.lang.String, Database type: java.lang.String, Allow null: no, Size: 20, Truncated: false, Fulltext indexed: false, Default value: , Collation: default"
4 = {EnumField@12918} "Name: type, DbName: type, Pos: 11, Type: se.netset.phrases.po.AteaPersistentPhrase$PhraseType, Database type: se.netset.phrases.po.AteaPersistentPhrase$PhraseType, Allow null: no"
rowTerminator = "\n"
file = "/tmp/bulktemp4584663740698327138.tmp"
The file contains a lot of rows, here is a snippet where line 2 and 3 are the ones causing the problem:
...
com.company.test REMOVE_PRODUCT Remove product 22451 0
com.company.test REMOVE_PRODUCT_START Do you wish to remove the product " 22451 1
com.company.test REMOVE_PRODUCT_END " from the report? 22451 1
com.company.test REPORT Report 22451 0
...
Row 2 and 3 contains " and should be treated as part of the string to be inserted to the table.
But it results in an IndexOutOfBoundsException:
at com.microsoft.sqlserver.jdbc.SQLServerBulkCSVFileRecord.getRowData(SQLServerBulkCSVFileRecord.java:325)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeBatchData(SQLServerBulkCopy.java:3717)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.doInsertBulk(SQLServerBulkCopy.java:1590)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy$1InsertBulk.doExecute(SQLServerBulkCopy.java:681)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7745)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:4700)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.sendBulkLoadBCP(SQLServerBulkCopy.java:715)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:1678)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:638)
....
This is because data[] only contains 3 strings instead of 5 as expected. So the problem is that SQLServerBulkCSVFileRecord:parseString(String buffer, String delimiter) is only returning an array of 3 instead of 5 Strings.
Expected behavior
It should be possible to bulk insert strings that contain "
Actual behavior
Described above.
Any other details that can be helpful
My code works as expected if I toggle to using versions prior to v12.7.1, when this commit was merged 722c910
Driver version
12.10.0.jre11
SQL Server version
Microsoft SQL Server 2019 (RTM-CU32-GDR) (KB5065222) - 15.0.4445.1 (X64) Aug 13 2025 11:07:18 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro 10.0 (Build 19045: )
Client Operating System
Ubuntu 24.04.3 LTS
JAVA/JVM version
Java 21 (openjdk 21.0.8 2025-07-15)
Problem description
Bulk insert does not handle string containing ".
I call the MsSqlServer:doBulkInsert with these parameters:
bulkInsertBase = {BulkInsertBase@12886}
rowCount = 17562
ignoreCount = 0
fieldsTerminatedBy = "\t"
value = {byte[1]@12923} [9]
coder = 0
hash = 9
hashIsZero = false
tableName = "syncphrase"
forceEmpty = false
recreateTable = true
keepIdentity = false
tableLock = false
fields = {Arrays$ArrayList@12911} size = 5
0 = {StringField@12914} "Name: namespace, DbName: namespace, Pos: 7, Type: java.lang.String, Database type: java.lang.String, Allow null: no, Size: 500, Truncated: false, Fulltext indexed: false, Default value: , Collation: default"
1 = {StringField@12915} "Name: key, DbName: key_, Pos: 6, Type: java.lang.String, Database type: java.lang.String, Allow null: no, Size: 500, Truncated: false, Fulltext indexed: false, Default value: , Collation: default"
2 = {StringField@12916} "Name: phrase_en, DbName: phrase_en, Pos: 4, Type: java.lang.String, Database type: java.lang.String, Allow null: no, Size: 2000, Truncated: false, Fulltext indexed: false, Default value: , Collation: default"
3 = {StringField@12917} "Name: taskId, DbName: taskId, Pos: 10, Type: java.lang.String, Database type: java.lang.String, Allow null: no, Size: 20, Truncated: false, Fulltext indexed: false, Default value: , Collation: default"
4 = {EnumField@12918} "Name: type, DbName: type, Pos: 11, Type: se.netset.phrases.po.AteaPersistentPhrase$PhraseType, Database type: se.netset.phrases.po.AteaPersistentPhrase$PhraseType, Allow null: no"
rowTerminator = "\n"
file = "/tmp/bulktemp4584663740698327138.tmp"
The file contains a lot of rows, here is a snippet where line 2 and 3 are the ones causing the problem:
...
com.company.test REMOVE_PRODUCT Remove product 22451 0
com.company.test REMOVE_PRODUCT_START Do you wish to remove the product " 22451 1
com.company.test REMOVE_PRODUCT_END " from the report? 22451 1
com.company.test REPORT Report 22451 0
...
Row 2 and 3 contains " and should be treated as part of the string to be inserted to the table.
But it results in an IndexOutOfBoundsException:
at com.microsoft.sqlserver.jdbc.SQLServerBulkCSVFileRecord.getRowData(SQLServerBulkCSVFileRecord.java:325)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeBatchData(SQLServerBulkCopy.java:3717)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.doInsertBulk(SQLServerBulkCopy.java:1590)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy$1InsertBulk.doExecute(SQLServerBulkCopy.java:681)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7745)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:4700)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.sendBulkLoadBCP(SQLServerBulkCopy.java:715)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:1678)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:638)
....
This is because data[] only contains 3 strings instead of 5 as expected. So the problem is that SQLServerBulkCSVFileRecord:parseString(String buffer, String delimiter) is only returning an array of 3 instead of 5 Strings.
Expected behavior
It should be possible to bulk insert strings that contain "
Actual behavior
Described above.
Any other details that can be helpful
My code works as expected if I toggle to using versions prior to v12.7.1, when this commit was merged 722c910