Bug #421 j-connector 3.0.7 can't conver between unicode and server-charset automatically
Submitted: 13 May 2003 3:41 Modified: 21 May 2003 8:00
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.0.7 OS:chinese windows2000 pro
Assigned to: CPU Architecture:Any

[13 May 2003 3:41] [ name withheld ]
Description:
I worked under Chinese Windows2000pro with sp3, my local language is set to GBK.
I have the mysql server 4.0.12 installed, and add a line into c:\winnt\my.ini at section [mysqld] :
    default-character-set=gbk
By the way, the string "gbk" must be lower case, or the server can't be started.
I use mysql-connector-java-3.0.7-stable.zip, and found the problem that, in java programs, if I insert a Chinese String into a table useing j-connector-3.0.7, both encoding and decoding is wrong. one solution is
    connection = DriverManager.getConnection( "jdbc:mysql://localhost/test?user=root&password=&useUnicode=true&characterEncoding=GBK" );
but, because I have told the mysql server "default-character-set=gbk", so the jdbc driver should do encoding/decoding automatically.
 
 

How to repeat:
see "description"

Suggested fix:
is it a bug?

com\mysql\jdbc\Connecter.java
move line 1969:
    this.doUnicode = true; // force the issue
to line 1964, just before the line
    try {

in com\mysql\jdbc\Connecter.java, line 1963, function "private void checkServerEncoding()", I guess the variable "Connecter.doUnicode" and method "Connecter.useUnicode()" indicates whether jdbc-driver should convert between unicode and mysql-server-charset. so I moved the line 1969 4 lines upper. so if the mysql-server-charset is mulity-bytes than single-byte, it can be encoding/decoding by JVM.
in fact I know little about the source code, but after this modification, the jdbc-driver works all right now.
 
anyway, I wish this problem could be fixed soon.
 
expecting your reply
yimsm@21cn.com
[21 May 2003 8:00] Mark Matthews
This should be fixed. You can test it in the latest nightly snapshot of Connector/J 3.0 from http://mmmysql.sourceforge.net/snapshots/stable/