UTF-8 from MySQL

J

Jonck

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
 
J

Jonck

My apologies, I meant to post this to c.l.j.databases but it went here
instead. I will repost to that group, please don't respond in this
thread.
Thanks, Jonck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top