Bug #61772 ResultSet.updateObject doesn't work with national Strings properly
Submitted: 6 Jul 2011 15:17 Modified: 7 Jul 2011 17:45
Reporter: Gregory Shrago Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.16 OS:MacOS
Assigned to: CPU Architecture:Any

[6 Jul 2011 15:17] Gregory Shrago
Description:
ResultSet.updateObject with a string with russian letters puts garbage in a table.

Database: MySQL/6.0.5-alpha-community
Driver Version: mysql-connector-java-5.1.16 ( Revision: ${bzr.revision-id} )
JDBC Version: 4.0

Connection properties:
useUnicode=true
characterEncoding=UTF-8
useOldUTF8Behavior	=true

How to repeat:
Create a table like this:

create table t (
  id integer primary key,
  data text
)  charset utf8 collate 'utf8_unicode_ci';
insert into t values(1, "text");

and try to modify data using JDBC editable result set API:
resultSet.updateObject(2, some_string_in_russian)

The following variants work OK:
resultSet.updateObject(2, some_string_in_russian.getBytes())
resultSet.updateObject(2, some_string_in_russian.getBytes("utf8"))
statement.execute("insert into t values (1, n'<some_string_in_russian>'")

Insert without "n"-prefix puts garbage as well:
statement.execute("insert into t values (1, '<some_string_in_russian>'")

so I think the problem is that Connector/J handles string parameter in updateObject just like 'xxx' and not an n'xxx' string.

Suggested fix:
I could not find any workaround to make updateObject work as expected.
[6 Jul 2011 19:40] Mark Matthews
MySQL-6.0.5 alpha is an unsupported version of the server. Does this same issue happen with a supported GA version of the server, i.e. MySQL-5.5.something?
[7 Jul 2011 16:19] Gregory Shrago
Same results with:

Database: MySQL/5.5.14
Driver Version: mysql-connector-java-5.1.16 ( Revision: ${bzr.revision-id} )
JDBC Version: 4.0
[7 Jul 2011 16:40] Tonci Grgin
Gregory, please please set useOldUTF8Behavior to FALSE and retest. useOldUTF8Behavior=true enforces MySQL server 4.0 compliant UTF8 string manipulation.
[7 Jul 2011 17:18] Gregory Shrago
Now 5.5 works.
But version 6 requires useOldUTF8Behavior=true otherwise it throws:

Can't establish connection to database
java.sql.SQLException: Unknown character set: 'utf8mb4'
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.Util.getInstance(Util.java:386)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619)
	at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1823)
	at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3496)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2385)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)

If it will be eventually supported then this case should be examined as well.
[7 Jul 2011 17:29] Tonci Grgin
Gregory, as Mark already said, MySQL-6.x is not supported version of the server as it is deprecated.
[7 Jul 2011 17:45] Gregory Shrago
In this case the ticket can be closed, thank you very much for your help.
[7 Jul 2011 17:47] Tonci Grgin
Gregory, thanks for using MySQL.