How can I retrieve string data from a database in Unicode format?

Joe Sam Shirah

The data is already in Unicode when it arrives in your program. Conversion from and to the encoding/charset/CCSID in the database from/to Unicode in the program is part of the JDBC driver's job.

If, for some reason, you want to see the data in 'uHHHH' format ( where 'H' is the hex value ), the following code, while not very efficient, should give you some ideas:


public class UniFormat
{

  public static void main( String[] args )
  {
    char[] ac = args[0].toCharArray();
    int iValue;
    String s = null;
    StringBuffer sb = new StringBuffer();

    for( int ndx = 0; ndx < ac.length; ndx++ )
    {
      iValue = ac[ndx];

      if( iValue < 0x10 )
      {
        s = "u000";
      }
      else
      if( iValue < 0x100 )
      {
        s = "u00";
      }
      else
      if( iValue < 0x1000 )
      {
        s = "u0";
      }

      sb.append( s + Integer.toHexString( iValue ) );
    } // end for

    System.out.println("The Unicode format of " + 
                          args[0] + " is " + sb );

  } // end main

} // end class UniFormat
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact