inserting utf8 data into DB
Hello Everybody
I'm using MySQL and I created database with UTF8_general_ci format
My problem is when I 'm inserting data from My Application and then retrieve data it looks like "?a?"
query="INSERT INTO app.employee(`ID`, `NAME`, `ADDRESS`, `PHONE`) VALUES (5, 'şöhratyň', 'street', '555555');";
statement.execute(query);
when I retrieve data it looks like this
5 ?öhraty? street 555555
but when I inserted that data from cmd its OK
I have tried to set connections property to utf 8 but it doesn't work too
please help
regards
Re: inserting utf8 data into DB
What encoding is your JVM using? System.getProperty("file.encoding") should tell you. Problems like these are usually caused by mismatched encodings on your platforms.
Re: inserting utf8 data into DB
Quote:
Originally Posted by
Sean4u
What encoding is your JVM using? System.getProperty("file.encoding") should tell you. Problems like these are usually caused by mismatched encodings on your platforms.
My JVM using UTF-8 encoding
Re: inserting utf8 data into DB
Look this site :
Unicode/UTF-8-character table
for example :
String string = "abc\u5639\u563b";
System.out.println(string);
Re: inserting utf8 data into DB
On the offchance it helps, I found an old config file from MySQL from a defunct Java project where I had similar problems. You need to specify utf8 for both the database and client connections. Here are the relevant parts from my old my.cnf:
Code :
[client]
default-character-set=utf8
[mysqld_safe]
collation_server=utf8_unicode_ci
character_set_server=utf8
I guess you don't need telling that changing the platform encodings won't 'fix' problems in existing data? You'll almost certainly have to empty your tables and repopulate them after an encoding change.