Getting UTF-8 strings from MySQL

This is a discussion on Getting UTF-8 strings from MySQL within the JDBC JAVA forums in Framework and Interface Programming category; 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 ...

Go Back   Application Development Forum > Framework and Interface Programming > JDBC JAVA

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 10-16-2004, 01:24 PM
Jonck
Guest
 
Default Getting UTF-8 strings from MySQL

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
Reply With Quote
  #2  
Old 10-19-2004, 04:52 AM
Patrik Jacoby
Guest
 
Default Re: Getting UTF-8 strings from MySQL

Hi,
just a hint:

is your test environment (e.g. shell) able to display utf-8 characters ?
the windows cmd.exe is not, in a browser you have to set the encoding
correctly.

Hope that helps,
Patrik



Jonck wrote:
> 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

Reply With Quote
  #3  
Old 10-20-2004, 05:55 AM
Yan Lijun
Guest
 
Default Re: Getting UTF-8 strings from MySQL

try this
jdbc:mysql://localhost:3306/edusuite?useUnicode=true&characterEncoding=UTF-8

ÔÚ Sat, 16 Oct 2004 17:24:10 GMT ʱ, Jonck <jonck@vanderkogel.net> дÁË:
--

>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


gumpagain@163.com
/**
/* Java Is Not Platform-independent.It Is The Platform!
*/
Reply With Quote
  #4  
Old 10-25-2004, 08:45 AM
Jonck
Guest
 
Default Re: Getting UTF-8 strings from MySQL

In <6edcn0ho7mh17s5n595snq4f6g3b0hcilr@news.yaako.com > Yan Lijun wrote:
> try this
> jdbc:mysql://localhost:3306/edusuite?useUnicode=true&amp;
> characterEncoding=UTF-8
>


Thank you very much, that worked perfectly!
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 06:58 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.