• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding insertion of Japanese charachters in UTF-8 database

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Can some one send me the code to insert Japanese data retrieved from a JSP page having shift-jis charset into an UTF-8 oracle database
I am interested in finding how do i convert the Japanese form data from Shift-JIS to UTF-8
i tried the following :
byte [] hibytes = ((String)request.getParameter("text_713")).getBytes("Shift_JIS");
initParameter = new String(hibytes, "utf-8");
out.println(initParameter);
but it does not work

Charset of my JSP Page is in Shift_JIS
Operating system : Sun Solaris
Let me know if you need any details
Thanks And Regards
Nitin
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The ServletRequest should take care of translating the original Shift-JIS data into a String - you shouldn't need to do anything special for this. And when you store data in the DB, the DB should take care of converting the String to UTF-8 bytes, if it's been properly configured. Unfortunately debugging this sort of thing is tricky, because it's hard to look at intermediate results to see if they're valid. You usually can't just write to System.out, because standard output doesn't know how to display Japanese characters. (Unless maybe you're running a machine configured for Japan; I don't know just how that works.) What I recommend for debugging is to write intermediate results to a file in HTML, and use your browser to look at the file and see what it looks like. (You could also create a simple GUI to display a JTextPane of the data, but in some contexts that's not convenient to have a GUI popping up - if you write a file, you can look at it later whenever it's convenient.)
Here's a start:

Note that the encoding used inside makeHTMLTestFile() has nothing to do with the encoding used by the JSP, or by the DB. It's just the encoding used for the test file. You can replace it with some other encoding, as long as it's one your browser understands and which can represent Japanese characters.
 
reply
    Bookmark Topic Watch Topic
  • New Topic