RE: Translated characters stored in database



I was able to reproduce the problem. Sorry about the confusion.

I filed a bug on this problem.

Thanks,
Kamil

Kamil Sykora
Microsoft Developer Support - Web Data

Please reply only to the newsgroups.
This posting is provided "AS IS" with no warranties, and confers no rights.


Are you secure? For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/secur­ity.



| From: kamils@xxxxxxxxxxxxxxxxxxxx (Kamil Sykora [MSFT])
| Organization: Microsoft Developer Support
| Date: Tue, 24 May 2005 16:12:13 GMT
| Subject: RE: Translated characters stored in database
|
| Hello,
|
| I tested your code with this binary data in the infile.txt:
|
| 20 21 22 23 24 25 26 27 28 29 30 7B 7C 7D 7E 7F 80 82 83 84 85 86 87 88
89
| 8A C0 C1 C2 C3 C4 C5 F0 F1 F2 F3 FE FF
|
| I then insert the data with the code below into the database. The result
is
| below. Note that the characters are probably not displaying correctly but
| the hex values should:
|
| select text, cast (text as varbinary(40)) from texttable
|
| text

|

|
|
----------------------------------------------------------------------------
| ------------------------
|
----------------------------------------------------------------------------
| ------
| !"#$%&'()0{|}~??????????ÀÁÂÃÄÅðñòóþÿ

|
|
0x20212223242526272829307B7C7D7E7F8082838485868788898AC0C1C2C3C4C5F0F1F2F3FE
| FF
|
|
| This is what I would expect. Are you seeing different results? If so,
what
| data are you seeing?
|
| Thanks,
| Kamil
|
| Kamil Sykora
| Microsoft Developer Support - Web Data
|
| Please reply only to the newsgroups.
| This posting is provided "AS IS" with no warranties, and confers no
rights.
|
|
| Are you secure? For information about the Strategic Technology
Protection
| Program and to order your FREE Security Tool Kit, please visit
| http://www.microsoft.com/secur­ity.
|
|
|
| --------------------
| | From: "=?Utf-8?B?QmlyY2hCYXJsb3c=?="
| <BirchBarlow@xxxxxxxxxxxxxxxxxxxxxxxxx>
| | Subject: Translated characters stored in database
| | Date: Sun, 22 May 2005 21:26:07 -0700
| | Lines: 43
| |
| | Is this a known issue? I am using the MS JDBC driver to connect to SQL
| | Server 2000 SP3a. The driver version is either SP2 or SP3. I tested
| both
| | with the same results. The database collation is Latin1. Sun java
1.3.1
| or
| | 1.4.2. When using the SendStringParametersAsUnicode=false in the
| connection
| | string the driver translates the characters in the 0x80 to 0x9f range.
| The
| | translation does not occur when setting the above connection parameter
to
| | true. I have also tested the Data Direct driver and there is no
| character
| | translation with the parameter true or false. I have enclosed a sample
| piece
| | of code to illustrate the issue. I need to use the parameter as false
| since
| | there is a significant performance hit with it set to true. Also my
| | application requires support for the full Latin1 (Windows 1252)
character
| | set. It looks like the character translation is a result of dropping
the
| | upper byte of the Unicode character which for all characters except
0x80
| -
| | 0x9f is 0x00. If you look at the Windows 1252 character set Unicode
| values
| | you will see that the 0x80 to 0x9f characters have a value in the upper
| byte
| | therefore simply truncating the upper byte produces a character
| translation.
| | Example: Character 0x80 has the Uniccode value of 0x20AC and is
| translated to
| | 0xAC in the database.
| |
| | table1:
| | varchar(300);
| |
| | file: infile.txt is a binary file with the characters bytes 0x20 to 0xff
| |
| | Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
| | con =
| |
|
DriverManager.getConnection("jdbc:microsoft:sqlserver://myserver;SelectMetho
|
d=cursor;SendStringParametersAsUnicode=false;user=test;password=test;Databas
| eName=TestDB"
| | );
| |
| | BufferedReader r = new BufferedReader(new FileReader("infile.txt"));
| | String text = r.readLine();
| |
| | PreparedStatement pstmt = null;
| | String sqlQuery = "insert into table1 (text) values (?)";
| |
| | pstmt = con.prepareStatement(sqlQuery);
| | pstmt.setString(1, text);
| | pstmt.execute();
| |
| | pstmt.close();
| | pstmt=null;
| | con.close();
| | con=null;
| |
|
|

.



Relevant Pages

  • RE: Translated characters stored in database
    ... | I then insert the data with the code below into the database. ... I am using the MS JDBC driver to connect to SQL ... | | translation with the parameter true or false. ...
    (microsoft.public.sqlserver.jdbcdriver)
  • RE: Translated characters stored in database
    ... Kamil & MSFT: ... > | I then insert the data with the code below into the database. ... > | | translation with the parameter true or false. ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: General programming question
    ... > Jim Brain wrote: ... >> inserts are done (you'd need to re-alloc the array and copy all ... > the vagaries of the translation as anything else, ... you then do is map from one charset character to the other (character ...
    (comp.sys.cbm)
  • Re: asymptote/hyperbola?
    ... He's presenting a character who's talking math. ... So a responsible reading will account for this nonsense in at least one ... Translation is the foundation of every reading. ... >> On your last hermeneutic occasion, you informed us that all the dancer ...
    (rec.arts.books)
  • Long - About ASCII backslash codes (was: A few more questions in How to keep PI in symbolic form
    ... LineFeed (character 10); ... If you need a reminder of the translation sequences, ... User-RPL program for the 49 series builds a handy string with the ... its translation sequence appears in the last column depends on the ...
    (comp.sys.hp48)

Loading