Getting UTF-8 strings from MySQL

From: Jonck (jonck_at_vanderkogel.net)
Date: 10/16/04


Date: Sat, 16 Oct 2004 17:24:10 GMT

Hi everybody,
I'm having problems retrieving strings from MySQL in UTF-8. I know (or
at least I'm pretty sure) that the strings are being written to the
database correctly, because when I use the mysql command-line utility
and do a SELECT I see the correct strings there.
However, when I retrieve the strings they are not formatted correctly.
For example, if I write the string "Knäckebröt" to the database and then
try to retrieve it, it comes out as "Kn�ckebröt".

I read the Connector/J manual, where it tells me to do the following to
write and read UTF-8 strings to and from MySQL:
When opening a connection with MySQL I should use the following code:
Properties props = new Properties();
props.setProperty("characterEncoding", "utf-8");
conn = DriverManager.getConnection(connectionString, props);

However, when I now try to read a string from a resultset, for example (
where results is a JDBC ResultSet):
String messageText = results.getString("messageText");

the text comes out garbled.

Does anybody have any suggestions for me to be able to retrieve the text
with the correct encoding?

Thanks very much, Jonck



Relevant Pages

  • Re: Getting UTF-8 strings from MySQL
    ... >I'm having problems retrieving strings from MySQL in UTF-8. ... when I retrieve the strings they are not formatted correctly. ...
    (comp.lang.java.databases)
  • UTF-8 from MySQL
    ... I'm having problems retrieving strings from MySQL in UTF-8. ... when I retrieve the strings they are not formatted correctly. ...
    (comp.lang.java.programmer)
  • Re: "10.98" from MySQL shows up as "10.9799995422" in PHP - why?
    ... he was right because MySQL has built-in capability to handle decimal numbers. ... Sometimes when you're doing something unusual, you have to figure out if you can map the data type you have onto an existing data type to achieve this. ... It can do it with strings. ...
    (comp.lang.php)
  • Re: escaping vs stored procedure
    ... it's really (PHP's MySQL library)'s function? ... It is a library function in MySQL. ... ng that mysql_escape_string prevents sql injection. ... mysql_real_escape_stringstrings, ...
    (comp.lang.php)
  • Re: "10.98" from MySQL shows up as "10.9799995422" in PHP - why?
    ... b)There is one poster who called my suggestion to map floats onto strings ... It's not just MySQL. ... However, if that doesn't work, mapping onto strings is the next logical ...
    (comp.lang.php)