• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Charset Conversion

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Park Linkin wrote:



Welcome to the Ranch.
Please check your private messages for an important administrative matter.
 
Sheriff
Posts: 28344
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This article was written specifically to answer your question: Character Conversion from Browser to Database.
 
Nitin D Gaur
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).
 
Nitin D Gaur
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Slime does not pay. Always keep your tiny ad dry.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic