A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Reg loading Unicode data from DB
Joined: Dec 17, 2003
Aug 29, 2008 04:25:00
I have a basic doubt wrt to ensuring internationalization support in Java applications. In my Java code, I try to "enforce" UTF8 encoding by doing:
PreparedStatement pst = connection.prepareStatement("SELECT..."); ResultSet rst = pst.executeQuery(); ... String myInternationaltring = rst.getString("UniString"); String utf8String = new String(myInternationaltring .getBytes("UTF8"));
However, when the data value in the database is
, the resultant
is mangled up :
However if I remove the encoding and just retain the String in the above code:
PreparedStatement pst = connection.prepareStatement("SELECT..."); ResultSet rst = pst.executeQuery(); ... String myInternationaltring = rst.getString("UniString"); String utf8String = new String(myInternationaltring);
the output is fine:[CODE]Localiza��o Amostra[/CPDE]
I am collecting information on the database but it might be UTF-16 as well. I am unclear on what I am doing wrong and what I should be doing to ensure internalionalization completely.
Could any kind soul pl help?
Joined: Oct 14, 2005
Aug 29, 2008 09:17:00
String myInternationaltring = rst.getString("UniString");
and nothing else. The database driver and the database between them should take care of any encoding issues. And from what you say in your second example, that is already working. I don't understand why you think you have to do anything else.
Don't get me started about those stupid
subject: Reg loading Unicode data from DB
problem in copying table
populate data from database into a jtable
problem with ResultSet
Displaying Image stored in MSSQL Server
How to check query within PreparedStatement object
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014