This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Charset Conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Charset Conversion" Watch "Charset Conversion" New topic
Author

Charset Conversion

Nitin D Gaur
Greenhorn

Joined: Jul 04, 2008
Posts: 10
Hi All,

I am facing one problem with thai character encoding. I have some jsp pages for a mobile web application where I show some static thai text and some text is being fetched from Database tables. I am using Content-Type as "text/html; charset=utf-8".

The problem is the static thai text is appearing properly on mobile browsers but the text, fetched from database is not proper. its apearing like this "ÃËÑÊ»ÃШӵÑÇ" (This is the thai encoding I guess saved in database)
What could be the solution for this ?

If I use the static thai text in jsps as TIS-620 encoding and Content-Type as "text/html; charset=TIS-620". Than static and DB thai text both is coming properly. But only for some mobile browsers. May be these browsers support TIS-620 and others dont.

I have checked about java.nio.charset package, but could not find any working example over the net to convert TIS-620 text "ÃËÑÊ»ÃШӵÑÇ" to UTF-8.

is it possible to convert text from one charset encoding to other ?

Please help me. If I could not make you all understand the problem properly please let me know.

Nitin
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8439

Park Linkin wrote:


Welcome to the Ranch.
Please check your private messages for an important administrative matter.


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

This article was written specifically to answer your question: Character Conversion from Browser to Database.
Nitin D Gaur
Greenhorn

Joined: Jul 04, 2008
Posts: 10
Hi Paul,

thanks for your reply, but how to take data form browser to DB is not my problem.

my problem is how to convert data into utf-8 to be shown on browser.

If i use character encoding as windows-874 or tis-620 than its possible, but some mobile browsers dont support tis-620 and windows-874. Thats why I want to make data from DB, compatible to utf-8.

Nitin
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35250
    
    7
my problem is how to convert data into utf-8 to be shown on browser.

Are you encountering an actual problem? Assuming that the DB charset is configured correctly, and you're using JDBC to access the DB, then what you get from the DB should be standard Java strings that you can just print to the JSP page (assuming that's correctly configured to show UTF-8).


Android appsImageJ pluginsJava web charts
Nitin D Gaur
Greenhorn

Joined: Jul 04, 2008
Posts: 10
The String which I am getting from DB is like this "¸¹Ò¤ÒÃ¡ÃØ§à·¾" this is actually thai encoding in TIS-620 or windows-874..... I cant change DB data or conf.

what I need do is to convert this string to UTF-8, so that it could be shown on Browser.

I know that this can be done through java.nio.charset. But how I am not able to figure out.

Nitin.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35250
    
    7
Are you certain that it is stored correctly in the DB? A DB is configured for one -and only one- charset; which one is that in your case? You can't store data in various different charsets in a DB and expect it to get out correctly.
Nitin D Gaur
Greenhorn

Joined: Jul 04, 2008
Posts: 10
Dont be prejudice Man !!! That I am wrong.

if I use meta tag in my JSPs as.

<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
or
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />

I can manage to get proper results with the data from DB.

But when I change it to <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

I get junk characters. I have to use utf-8 content type only becasue tis-620 and windows-874 is not supported on all mobile devices.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Charset Conversion
 
Similar Threads
content type overides my encoding
arabic data from the database
Problem in Displaying Non english content in a UTF-8 JSP
Urgent -Need an API to identify the character encoding
saving chinese data to text file