Skip to content

Lost nvarchar parameters. #437

@halfspawn

Description

@halfspawn

Driver version or jar name

All versions (4.1, build from git source)

SQL Server version

All versions (2008 to 2016)

Client operating system

Windows 10, Centos 7.3

Java/JVM version

java version "1.8.0_141"

Table schema

Please tell us the table schema

Problem description

With sendStringParametersAsUnicode=true (default),
Use of SetNull(position, Types.VARCHAR) on a NVARCHAR output parameter of a stored procedure, bind a varchar variable --> lost of nvarchar character.

Expected behavior and actual behavior

If sendStringParametersAsUnicode=true, act as SetNull(position, Types.NVARCHAR)

Repro code

    String polishchar = "\u0143";
    m_cnx.createStatement().execute(
            "create procedure proc1(@p1 nvarchar(255), @p2 nvarchar(255) output) as select @p2=@p1 return 0");
    cs=m_cnx.prepareCall("{?=call proc1(?,?)}");           
    cs.registerOutParameter (1, Types.INTEGER);
    cs.setString(2,polishchar);
    cs.setNull(3, Types.VARCHAR);
    cs.registerOutParameter (3, Types.VARCHAR);        
    cs.execute();
    String p2=cs.getString(3);
    
    System.out.println("p1="+polishchar+" p2="+p2);

    cs=m_cnx.prepareCall("{?=call proc1(?,?)}");           
    cs.registerOutParameter (1, Types.INTEGER);
    cs.setString(2,polishchar);
    cs.setString(3, ""); 
    cs.registerOutParameter (3, Types.VARCHAR);        
    cs.execute();
    p2=cs.getString(3);
    
    System.out.println("p1="+polishchar+" p2="+p2);

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