Re: WE8ISO8859P1 convert to AL32UTF8 unicode character set question

From: lsllcm <lsllcm_at_gmail.com>
Date: Sat, 11 Apr 2009 22:14:31 -0700 (PDT)
Message-ID: <55947418-01c2-4257-a082-98659d481b0b_at_j18g2000prm.googlegroups.com>



I have done more test on conversion between java client and oracle db server. Below are test code.
-----------Code begin -------------------------

      byte[] bRay = null;
      char quote = '"';
      int ndx;
//      String sInitial = "Enc" + "\u4E94";
      String sInitial = rs.getString("c1");

      try { bRay = sInitial.getBytes("UTF-16"); }
      catch( UnsupportedEncodingException  uee )

{
System.out.println( "Exception: " + uee); } System.out.println( quote + sInitial + quote + " String as UTF-16, " + "bRay length: " + bRay.length + "." ); for( ndx = 0; ndx < bRay.length; ndx++ )
{
System.out.print( Integer.toHexString( bRay[ ndx++ ] ) + " " ); System.out.print( Integer.toHexString( bRay[ ndx ] ) + " " ); } System.out.println("\n"); OutputStreamWriter osw = new OutputStreamWriter( System.out ); bRay = sInitial.getBytes(); System.out.println( quote + sInitial + quote + " String as platform default - " + osw.getEncoding() + ", bRay length: " + bRay.length + "." ); for( ndx = 0; ndx < bRay.length; ndx++ )
{
System.out.print( Integer.toHexString( bRay[ ndx ] ) + " " ); } System.out.println("\n"); try
{
sInitial = new String( sInitial.getBytes("UTF-8"), "UTF-8"); bRay = sInitial.getBytes("UTF-8"); } catch( UnsupportedEncodingException uee )
{
System.out.println( "Exception: " + uee); } System.out.println( quote + sInitial + quote + " String as UTF-8, " + "bRay length: " + bRay.length + "." ); for( ndx = 0; ndx < bRay.length; ndx++ )
{
System.out.print( Integer.toHexString( bRay[ ndx ] ) + " " ); } -----------Code begin -------------------------
  1. Below are test result when the db is AL32UTF8 when the row has data "sys.¡­Med ."
-----------test result begin -------------------
"sys.…Med" String as UTF-16, bRay length: 18.. fffffffe ffffffff 0 73 0 79 0 73 0 2e 20 26 0 4d 0 65 0 64

"sys.…Med" String as platform default - Cp1252, bRay length: 8.. 73 79 73 2e ffffff85 4d 65 64

"sys.…Med" String as UTF-8, bRay length: 10.. 73 79 73 2e ffffffe2 ffffff80 ffffffa6 4d 65 64 windows

-----------test result end ----------------------

2. Below are test result when the db is WE8ISO8859P1 when the row has data "sys. Med ."

-----------test result begin -------------------
"sys.?Med" String as UTF-16, bRay length: 18. fffffffe ffffffff 0 73 0 79 0 73 0 2e 0 ffffff85 0 4d 0 65 0 64

"sys.?Med" String as platform default - Cp1252, bRay length: 8. 73 79 73 2e 3f 4d 65 64

"sys.?Med" String as UTF-8, bRay length: 9. 73 79 73 2e ffffffc2 ffffff85 4d 65 64 windows-1252

-----------test result end ----------------------

4. I use FileOutputStream to print the data into file and open it by using IE, the result is same as in JSP.

--------code begin------------
FileOutputStream fs=new FileOutputStream( "aa.htm");

OutputStreamWriter oswaa = new OutputStreamWriter( fs, "UTF-8" );

bb = rs.getString("c1");
oswaa.write(bb,0,bb.length());
--------code end------------

Conclusion:

The java client read data from oracle and translate it into UTF-16, but how to print the data from java applicaiton, we need to do encoding-decoding work. Received on Sun Apr 12 2009 - 00:14:31 CDT

Original text of this message