Re: sendStringParameterAsUnicode: How to insert unicode data correctly

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance





sm wrote:

When inserting unicode data, we would like to programmatically override the setting and send the data encoded in unicode(UTF-16), instead of defaulting the whole app to unicode=true and take a performance hit.


Configuration: MS SQL server 2005 SP2, and MS jdbc driver version: 1.1
The sendStringParameterAsUnicode has been set to false for performance reasons. Any suggestions? We have tried the cast(? as nvarchar) function, but that did not help.

Sample code/output:
String text = "\u0143\u0144";
sendStringParametersAsUnicode=false
insert into unitable (_ntext) values (?)
Inserting into databse:
143 144 (printed hex values)
Read from database:
3f 3f (printed hex values)

Thanks,
sm.

Hi. Your choices are only two:

1 - the default (sendStringParameterAsUnicode=true). This
means the driver will send Java strings as 16-bit characters.
This is the default because Java characters are 16-bit, and
no driver would presume to automatically mutate your data.

2 - sendStringParameterAsUnicode=false. This means the driver
will send Java strings as 8-bit characters, *silently truncating
any high-byte content before sending*. That's why you saw what
you saw.

You want/need the first if your strings have chars with any
non-zero high-order bytes.

There is no performance issue to speak of in the *sending*
of data. The main issue is whether the DBMS will use the
table indexes when searching with the sent data as search
criteria. If data is sent as 16-bit, it will use any NVARCHAR
indexes, but not VARCHAR indexes. If it is sent as 8-bit, it
will use VARCHAR indexes, but not NVARCHAR.
So as long as you make sure you send the data as you need,
you're OK. If you send as 16-bit to compare to VARCHAR columns,
the DBMS will skip indexes and do table scans. That is where
the pain comes in.

Joe Weinstein at BEA Systems

.



Relevant Pages

  • Re: Inserting flow-control chars with an mpsafetty kernel
    ... ^Q characters cannot be inserted inserted anymore. ... TTY code, but it is not so directly involved in the handling of the ... When I implemented the ptsdriver, I thought the idea behind TIOCPKT ...
    (freebsd-current)
  • Re: xPC Serial Communication Problems
    ... We're using the serial ports that come on the CPU ... The older serial block you're using uses the kernel resident driver ... Is the receiving machine executing at the 'same' 50 ms rate? ... does it wait until there are at least 15 characters in the ...
    (comp.soft-sys.matlab)
  • Re: Bytes
    ... architecture, for the following reasons: ... to make Windows NT driver support easier. ... convert between wide characters and multibyte characters and this is ... be simply mapped to multibyte characters in C, ...
    (comp.lang.forth)
  • Re: Palatable Windows IO using Ada
    ... have seen for the Win32 API simply export the ReadFile and ReadFileEx ... characters exceeding some threshold. ... used to implement a bi-directional communications driver. ...
    (comp.lang.ada)
  • Re: strings - reading utf8 characters such as japanese. how?
    ... characters instead of asc characters, ... Why are you working in UTF8 using Java Strings? ... If you want to load your information into /text/, let Java decode the external ...
    (comp.lang.java.programmer)