Skip to content

Bulkcopy fails when inserting non-unicode multibyte String. #1414

@kmzxy

Description

@kmzxy

Driver version

mssql-jdbc-8.4.0.jre11.jar

SQL Server version

Microsoft SQL Server 2017 (RTM-GDR) (KB4505224) - 14.0.2027.2 (X64) Jun 15 2019 00:26:19 Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2016 Standard 10.0 (Build 14393: ) (Hypervisor)

Client Operating System

Windows 10

JAVA/JVM version

RedHat OpenJDK
openjdk version "11.0.8" 2020-07-14 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.8+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode)

Table schema

CREATE TABLE [dbo].[TEST](
	[name] [varchar](10) COLLATE Japanese_CS_AS_KS_WS NOT NULL
)

Problem description

  1. Expected behaviour:
    One row has been bulk-inserted.

  2. Actual behaviour:
    SQL Exception occured.

  3. Error message/stack trace:
    Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: (... (Japanese message))

  4. Any other details that can be helpful:
    In SQLBulkCopy.java, Line Around 2292 (commit-id 4e3ab66):

2292: tdsWriter.writeShort((short) (colValueStr.length()));

I think the above code should be something like this:
tdsWriter.writeShort((short) (colValueStr.getBytes(destColumnMetadata.get(destColOrdinal).collation.getCharset()).length));
when destCollation is not null.
Because colValueStr.length() is different from the transferred byte size by tdsWriter.writeBytes();

Bulk.java.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions