Bo's blog

Tuesday, September 06, 2011

java string encoding when reading from database

If the data you stored in the database is ISO-8859-1, then when you read the data from database you'd better use:  
String str = new String(rs.getBytes("message_fr"),"ISO-8859-1"); to avoid the encoding issue.

If the application is started in UTF-8 encoding, then the following statement will read the data as UTF-8 encoding:
String str =rs.getString("message_fr")

0 Comments:

Post a Comment

<< Home