MySQL encoding
mam problem v Debiane vkladat do MySQL UTF-8 diakritiku s JAVA MySQL connector. Vkladam do databazy nieco taketo:
exeQuery(new String(("insert into db values('FILEEE','ľščťžýáíé','éíáýžťčšľ','éíáýžťčšľ',2001,133,-1,45999,1526,'íáýžťčš')").getBytes("UTF-8"), "UTF-8"));
kde funkcia exeQuery vyzera standardne:
private void exeQuery(String query) {
try {
Statement s = (Statement) conn.createStatement();
s.execute(query);
} catch (SQLException ex) {
System.err.println(ex);
}
}
Problem ale nieje v JAVA, pretoze na Gentoo mi vlozi String spravne. Cela databaza aj tabulka aj atributy tabulky su nastavene na utf8_general_ci. Konzola je nastavena na UTF-8 a ak dam vypisat, co insertuje, tak je to spravne. Cize ak som to spravne pochopil JAVA vlozi spravny String, lenze v MySQL treba nieco nastavit?
Neviete v com by mohol byt problem?
Mam mysql-connector-java-5.1.13-bin. Na Debiane:
mysql Ver 14.12 Distrib 5.0.51a, for debian-linux-gnu (x86_64) using readline 5.2
Gentoo:
mysql Ver 14.14 Distrib 5.1.53, for pc-linux-gnu (i686) using readline 5.1.
Este dodam, ze phpMyAdmin vie vkladat spravne a vklada presne tak, ako vkladam cez JAVA.
Vdaka.
Pre pridávanie komentárov sa musíte prihlásiť.
SET CHARACTER SET utf8
private void mysqlConnect() {
try {
String url = "jdbc:mysql://" + mysqlServer + "/" + mysqlDb + "?useUnicode=true&characterEncoding=UTF-8";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = (Connection) DriverManager.getConnection(url, mysqlUser, mysqlPass);
System.out.println("Database connection established.");
} catch (Exception e) {
System.err.println("Cannot connect to database server.");
}
}