How can I retrieve string data from a database in Unicode format?
Location: http://www.jguru.com/faq/view.jsp?EID=285758 Created: Dec 26, 2000 Modified: 2000-12-26 02:14:24.367 Author: Joe Sam Shirah (http://www.jguru.com/guru/viewbio.jsp?EID=42100) Question originally posed by Jan Borchers (http://www.jguru.com/guru/viewbio.jsp?EID=48743 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