Um, Java Strings are already in Unicode. Or they should be. I'm guessing that perhaps your data got corrupted when it was read, or when it's written, and what you're doing now is repairing damage that was done elsewhere. If that's the case, it would probably be more effective to figure out how the damage occurred in the first place. Where are these strings getting read from, and where are they being written to? A file? A database? What java.io classes are you using to read the data? Probably you need to find classes methods that allow you to specify a character encoding.
Also, your method probably won't work correctly for non-European languages (and not even all European languages). If you have any Asian data, for example, you should try processing that to see if the results are acceptable.
"I'm not back." - Bill Harding, Twister
Joined: Feb 26, 2008
Hi Thank you for you reply.I think i did not explain my problem correctly.
Actually i read data from the DB which contains Japanese and Chinese characters. I do a resultset.getString(ColName) to get this data. Now i have to convert this to Unicode before i send the same to client side for processing. If i send without converting, it shows up as junk data. So is the method adopted by me correct?
Hi I connect to the appserver through XMLHttp. Yes,while sending data from client, as i send it as XML, i mention UTf-8. But while sending back, i pass it in the response text. If i don't convert, it shows up as junk. if i convert an get back in normal form in client, it works fine.
Joined: Feb 26, 2008
Hi All I'll give some more details about my problem. Well, fetching data and all is done at the server level,which is done in a DAO written in java. But my client is Excel and can be word too. SO if i send back data without converting to unicode, i get strange characters. I got help of a Japanese guy who suggested using unicode. No there is no issue in network transmission. Is there a problem if we send Japanese and Chinese characters in Microsoft products?
Joined: Mar 22, 2005
How do you know that there is no problem during transmission - have you made sure that all sides use the same transfer encoding?
You have a database? And you're extracting data from it and displaying it in a web application, and maybe getting data back from the user and putting that into the database? Then you must read Character Conversions from Browser to Database.
Originally posted by Jhakda Velu: ..Yes,while sending data from client, as i send it as XML, i mention UTf-8. But while sending back, i pass it in the response text. If i don't convert, it shows up as junk.
If i am right, by default the response will contain its 'contentType' as 'text/html'. In that case, obviously it will show as junk characters only.
if i convert an get back in normal form in client, it works fine.
What is this line means? How do you process it once you get the data?
Hi All Thanks all for your responses. Well, i don't use a browser. I have excel as front end and i need to fetch data from the DB. I connect to the App server thru a XMLHttp call. This hits teh servlet running on the app server and from htere flow is like a normal web app (service--> DAO--> DBand back). And a correction, i write the data i get into the ServletOutputStream as a String.
This data is got back at the client(excel) and displayed after doing some processing using vb macros.
The reason i say there is no error in transmission(though i can't say that i'm 100% sure) is that i do the tests on Appserver running on my machine,and i'd have tested around 50 times each with and without converting each literal i get from the db. Each time i do the conversion,it shows up fine and doesn't work otehrwise. I'd go through the links mentioned to me anyway, but i would like to ask waht would happen if i do a resultset.getString (1) where col number 1 contains Chinese/Japanese data in the DB. Please don't ask me not to use Excel as the front end as the users are hell bent on it and the person who gathered the requirements couldn't convert them
Hi All To add more information, intially i thought that as i'm running an English version of the OS, Japanese data is displayed incorrectly because of it(it appears as a ? but upside down). I then got a system running Japanese version of the OS, but the problem remained.