aspose file tools*
The moose likes JDBC and the fly likes problem with unicode database web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem with unicode database web application" Watch "problem with unicode database web application" New topic

problem with unicode database web application

sai suresh

Joined: Jan 02, 2004
Posts: 3
I'm trying to have a unicode enabled database for the web site I'm developing. The current installation is jdk1.4, postgres 7.3.2, jboss 3.2.3 on redhat linux9.0. The unicode seems to work well with normal jsp files with resource bundles. But when I try to input unicode characters into the database, the unicode data is not stored the way I expect. instead all unicode input is sored as a weird character resembling 'a'.
few of my concerns include
I input the unicode characters into form fields using my own javascript keypad(displays unicode characters when keys are pressed). So, if I understand clearly, its ok only for the browser frontend. So, immediately if I access the same unicode input from my servlet program and output the same in a console, its displaying junk. is it that my linux machine has some part to play in handling unicode?
I set the database encoding to unicode while creating the database. I'm also not sure whether the database is working the way I intended because, each unicode character is stored as a 3 character length weird data resembling an 'a' which supposedly be 1 character length.
my point is, even though there is problem inbetween while storing and retrieving the data from a database, it shouldn't matter because the brower is the one which takes the unicode input and it is the one which should display the retrieved data( which is not understood by my machine). I doubt, the unicode data is garbled when my machine handles the unicode data it gets from the browser.
did i miss anything? any suggestions or comments??
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
if the database doesn't store it correctly it can't send it back correctly either.
Possibly your JDBC driver (or the way you use it) can't handle Unicode and instead tries to save it all as single character ASCII thus causing the garbled data you're seeing.
Check what SQL datatype is expected. It may be that setString() from PreparedStatement doesn't work for you and you need setObject() instead.

sai suresh

Joined: Jan 02, 2004
Posts: 3
is there any source where I can know more about tewaking the JDBC to work with Unicode. also, how can i be sure its the jdbc thats the culprit. do you suggest any tests for this.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60077

Welcome to the Ranch "saisuresh "!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
JSP Forum Bartender
P.S. Since this topic is primarily DB-oriented, I'm moving this topic to the JDBC forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Benjamin Weaver
Ranch Hand

Joined: Apr 08, 2003
Posts: 161
I have heard about--but have not yet experienced first hand--a problem with PostgreSQL JDBC drivers and unicode. The workaround, I believe, was to call getBytes() instead of getString() when processing your resultSet. Do a search on getBytes() in the PostgreSQL search page. Maybe you will find this thread.
I agree. Here's the link:
subject: problem with unicode database web application
Similar Threads
problem with unicode strings in dynamic jsps
JDBC unicode conversion issue
Passing MultiLingual characters from a jsp
Understanding Byte Data and Character Encoding
Inserting Japanese text into Oracle database