I am using MySQL 5.6.27, Java Connector 5.1.36 on Linux, and I have problem with some of the Serbian/Croatian/Slovenian characters.
Database is started with
./bin/mysqld_safe --user=mysql --bind_address=localhost --character-set-server=utf8 &
Database is created with
-- CREATE USER 'my_test'@'localhost' IDENTIFIED BY 'my_test';
-- CREATE DATABASE my_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
-- GRANT ALL PRIVILEGES ON my_test.* TO 'my_test'@'localhost' IDENTIFIED BY 'my_test';
USE my_test;
CREATE TABLE proba
(
content TEXT NOT NULL
) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
INSERT INTO proba(content)
VALUES ('markovič marko SURČIN');
INSERT INTO proba(content)
VALUES ('Nikolić Nikola Ćićevac');
INSERT INTO proba(content)
VALUES ('petroviš đura Đeram');
INSERT INTO proba(content)
VALUES ('Milošević Miloš Šabac');
INSERT INTO proba(content)
VALUES ('jovanović žarko Žarkovo');
This dump is imported into MySQL with
/usr/local/mysql-5.6.27/bin/mysql --user=my_test --password < schema.sql
Java client fetches data with
public class Serbian
{
public static void main(String[] args) throws ClassNotFoundException, SQLException
{
Connection conn = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_test?user=my_test&password=my_test&useUnicode=true&characterEncoding=UTF-8&collation=utf8_unicode_ci");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT content FROM proba");
while(rs.next())
{
String s = rs.getString("content");
System.out.println(s);
}
rs.close();
}
catch (SQLException exc)
{
exc.printStackTrace();
}
finally
{
conn.close();
}
}
}
The result is
markovič marko SUR??IN
Nikoli?? Nikola ??i??evac
petroviš ??ura Đeram
Miloševi?? Miloš Šabac
jovanovi?? žarko Žarkovo
(question marks are actually invalid characters reported by editor). In other words, letters Č, Ć, ć, đ are invalid while Ž, ž, č, Š, š, Đ are valid. It's weird that UTF8 partially works. Is there something that I should give a try or this seems to be a MySQL/Java Connector problem?