Re: Java UTF-8 String

From: Siddhant Kaul (siddhant@cal.indiax.com)
Date: Tue Jul 08 1997 - 10:20:50 EDT


>Another possible interpretation of your question, though, is simply, "is
>it possible to create a Java String from a byte array if that byte array
>represents a series of characters encoded in UTF-8?"
>
>Yes, it certainly is, and it's one of the nicest features of Java for
>i18n fans. You just do this:
>
>String myString = new String(myUTF8ByteArray, "UTF8");
>
>That would take your UTF-8 bytes and turn them into a valid Java String
conntaining the chars you expected.

I didn't specify the reason for wanting to do so, which I probably
should have. I have a Chinese UTF8 database in Sybase SQL, which I
need to access through Java (using the JDBC-ODBC bridge) The user
inputs strings (in Traditional Chinese NT - Big5) and I query the
UTF8 database with the input strings.
Using a new approach I have been able to convert the user input
strings to UTF8 , and store them in a file (using the
outputStreamWriter(ouputStream, encoding) method. Now I need to use
the contents of that file to build my query. (fior example : select
item from table where item = <inputUTF8chars> )So in other words I
need Java to pass to the databse <inputUTF8chars> it doing any kind
of conversions to inputUTF8chars. I tried to do this by reading
from the file with the UTF8 chars, one character at a time using an
ordinary fileReader and appending them to a stringBuffer,
constructing the string from the stringBuffer, and finally pssing
the string. The code worked for some strings, but threw
SQLExceptions with other strings.
Is anything (or maybe a lot :) ) that I'm missing or doing wrong
here?



This archive was generated by hypermail 2.1.2 : Tue Jul 10 2001 - 17:20:35 EDT