Re: character set encoding bug in connector 5.1.36/5.1.37?
Posted by: Lars Gråmark
Date: October 29, 2015 08:30AM

I'm not sure this is related but I think there is a problem with the cacheServerConfiguration setting.
In my testcase I have two connections; c1 and c2. When c1 is established, it automatically loads the
server variables with the following:

{wait_timeout=28800, system_time_zone=CET, max_allowed_packet=524288000, net_buffer_length=16384, tx_isolation=REPEATABLE-READ, query_cache_size=1048576, character_set_server=latin1, auto_increment_increment=1, net_write_timeout=60, init_connect=, time_zone=+00:00, sql_mode=NO_ENGINE_SUBSTITUTION, character_set_results=utf8, query_cache_type=OFF, character_set_client=utf8, interactive_timeout=28800, lower_case_table_names=0, character_set_connection=utf8, license=GPL}

Right after this, a 'SET NAMES latin1' statement is sent to the server and two server variables are changed to

Now, when the second connection is established, the server variables are not loaded due to the cache. No 'SET NAMES latin1' is executed since the cached map values already contains the expected latin1 values on character_set_client and character_set_connection.
The consequence of this a SQLException when executing the second statement. The error message is "incorrect string value: '\xC0' for column 'c1'".
If I set characterEncoding to utf8 everything works fine. This behaviour wasn't in driver version 5.1.32. I haven't checked the versions between 32 and 37.

public static void main(String[] args) {
// create table mytable (id int not null, c1 varchar(50) CHARACTER SET latin1 COLLATE latin1_swedish_ci null);

try {
Properties p = new Properties();
p.setProperty("cacheServerConfiguration", "true");
// p.setProperty("characterEncoding", "utf8");
p.setProperty("user", "msandbox");
p.setProperty("password", "msandbox");

JDBC4Connection c1 = new JDBC4Connection("localhost", 5617, p, "mydatabase", "jdbc:mysql://localhost:5617/mydatabase");
PreparedStatement s1 = c1.prepareStatement("insert into mytable(id, c1) values (1, ?)");
s1.setString(1, "abcdefgh\u00C0");

JDBC4Connection c2 = new JDBC4Connection("localhost", 5617, p, "mydatabase", "jdbc:mysql://localhost:5617/mydatabase");
PreparedStatement s2 = c2.prepareStatement("insert into mytable(id, c1) values (2, ?)");
s2.setString(1, "abcdefgh\u00C0");
catch (Exception e) {

Options: ReplyQuote

Written By
Re: character set encoding bug in connector 5.1.36/5.1.37?
October 29, 2015 08:30AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.