Bug #2533 MySQL Connector does not recognize server encoding
Submitted: 27 Jan 2004 4:54 Modified: 27 Jan 2004 6:45
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version: OS:
Assigned to: CPU Architecture:Any

[27 Jan 2004 4:54] [ name withheld ]
Description:
When using MySQL Connector/J 3.0.9 stable and MySQL Server 4.1.1-alpha-standard-log the client can't determine the servers character encoding. This is due the fact that the method checkServerEncoding() in class com.mysql.jdbc.Connection looks up a variable named 'character_set', but the server uses 'character_set_server'.

How to repeat:
public void testEncoding() throws SQLException {
    org.gjt.mm.mysql.Driver driver = new org.gjt.mm.mysql.Driver();
    Connection conn = driver.connect("jdbc:mysql://host/db?user=hans&password=pass",null);
    Statement statement = conn.createStatement();
    result = statement.executeQuery("SELECT 'äöüß'");
    if (result.next()) {
        if(result.getString(1).equals('äöüß')) {
            // bug does not exist
        } else {
            // bug does exist
        }
    }
}

Suggested fix:
substitute

String serverEncoding = (String) this.serverVariables.get("character_set");

with

String serverEncoding = (String) this.serverVariables.get("character_set");
if (serverEncoding == null) {
    serverEncoding = (String) this.serverVariables.get("character_set_server");
}

in class com.mysql.jdbc.Connection
[27 Jan 2004 6:45] Mark Matthews
Thank you for your bug report. This issue has already been fixed
in the latest released version of that product, which you can download at 
http://www.mysql.com/downloads/
[27 Jan 2004 6:45] Mark Matthews
This was fixed in version 3.0.10.