Wednesday, November 08, 2006

Java UTF8 and MySQL / JDBC

So if you have ever had the joy of trying to figure out why the hell java wont store UTF8 data correctly in a mysql table I have found the answer finally:

---- Orig Post ---- [ http://forums.mysql.com/read.php?39,43303,43303#msg-43303 ]
I have problems updating data in utf-8 table using JDBC's PreparedStatement. I use something like:

PreparedStatement stmt=conn.prepareStatement("UPDATE tab SET field=?");
stmt.setString(1, str);
stmt.executeUpdate();

Non-ASCII chars int str are converted into question marks. I can read utf-8 data without problems but updating is a bit problem. Updates via mysql console is problem-less as well as PHP. But those question marks are...simple said - problem.

Could somebody give me some advice?

Thanks,
Lukas
------------------------------------

To which the answer was

---- Post -------- [ http://forums.mysql.com/read.php?39,43303,43373#msg-43373 ]
Solved...
I had to use useUnicode=true&characterEncoding=UTF-8 in connection string... Now everything works fine.
-------------------

Guess what it actally works!!!

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home