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

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

Closed
kmzxy opened this issue Aug 26, 2020 · 2 comments
Closed

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

kmzxy opened this issue Aug 26, 2020 · 2 comments
Projects

Comments

@kmzxy
Copy link

kmzxy commented Aug 26, 2020

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

@peterbae
Copy link
Contributor

Thanks for reporting this issue @kmzxy, your fix seems good and I'll make a PR as soon as testing is concluded.

@ulvii
Copy link
Contributor

ulvii commented Sep 16, 2020

#1421 merged.

@ulvii ulvii closed this as completed Sep 16, 2020
MSSQL JDBC automation moved this from In progress to Closed Issues Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
MSSQL JDBC
  
Closed Issues
Development

No branches or pull requests

3 participants