Bug #27867 ResultSetMetaData.getColumnName on a Chinese column return '??' but 5.0.4 is ok
Submitted: 17 Apr 2007 1:53 Modified: 11 Sep 2007 17:06
Reporter: Liu Yan Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:5.0.5 OS:Windows
Assigned to: CPU Architecture:Any
Tags: Chinese, getColumnName, Multi Bytes, ResultSetMetaData, RSMD

[17 Apr 2007 1:53] Liu Yan
Description:
as description in the title.

My environments:

Server:
-- OS: Windows Server 2003 Simplified Chinese + SP2
-- MySQL 5.0.37 community edition
-- JDK 1.5.0_11
-- Tomcat 5.5.20
-- MySQL Connector/J 5.0.5

Client:
-- OS: Windows XP Simplified Chinese + SP2
-- MySQL 5.0.37 community edition
-- JDK 1.6.0 Update 1

How to repeat:
1. create a table like this: 

mysql> set character set gbk;
mysql> use test;
mysql> show create table ColumnNameEncoding\G
CREATE TABLE `ColumnNameEncoding` (
  `中文测试` varchar(1) default NULL,
  `ASCIIColumn` varchar(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8

2. create a new Java file named 'ColumnEncodingTest.java' and compile it. (change the username & password parameters before compile) 

import java.sql.*;

public class ColumnEncodingTest
{
	public static void main (String[] args)
	{
		try
		{
			Class.forName ("com.mysql.jdbc.Driver");
			Connection conn = DriverManager.getConnection ("jdbc:mysql://localhost/test", "__DB_USERNAME__", "__DB_PASSWORD__");
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery("SELECT * FROM ColumnNameEncoding LIMIT 0,1");
			ResultSetMetaData rsmd= rs.getMetaData ();
			for (int i=1; i<=rsmd.getColumnCount(); i++)
			{
				System.out.println ("Column " + i + ": " + rsmd.getColumnName(i));
			}

			rs.close ();
			stmt.close ();
			conn.close ();
			
		}
		catch (Exception e)
		{
			System.err.println (e);
		}
	}
};

3.run the Java program with 5.0.5 driver and 5.0.4 driver separately and see the result: 

SHELL>java -cp .;mysql-connector-java-5.0.5-bin.jar ColumnEncodingTest
Column 1: ????–????è??
Column 2: ASCIIColumn

SHELL>java -cp .;mysql-connector-java-5.0.4-bin.jar ColumnEncodingTest
Column 1: 中文测试
Column 2: ASCIIColumn
[1 May 2007 18:49] Tonci Grgin
Hi and thanks for your report. Verified as described with latest c/J 5 sources and MySQL server 5.0.38BK on WinXP Pro SP2 localhost. Test case attached:
.Loading JDBC driver 'com.mysql.jdbc.Driver'
Done.

Done.

java.vm.version         : 1.5.0_11-b03
java.vm.vendor          : Sun Microsystems Inc.
java.runtime.version    : 1.5.0_11-b03
os.name                 : Windows XP
os.version              : null
sun.management.compiler : HotSpot Client Compiler
Connected to 5.0.38-log
1 .fld: 中?–‡?µ‹??•
2 .fld: ASCIIColumn

Time: 0,813

OK (1 test)
[1 May 2007 18:49] Tonci Grgin
Test case

Attachment: TestBug27867.java (text/x-java), 1.62 KiB.

[31 Aug 2007 0:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33493
[31 Aug 2007 1:20] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33495
[31 Aug 2007 1:25] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33496
[4 Sep 2007 18:45] Mark Matthews
Will be in 5.0.8/5.1.3.
[6 Sep 2007 15:14] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33832
[7 Sep 2007 14:04] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33909
[11 Sep 2007 16:41] MC Brown
A note has been added to the 5.0.8 and 5.1.3 changelogs: 

Schema objects with identifiers other than the connection character aren't retrieved correctly in ResultSetMetadata.
[11 Sep 2007 17:06] Liu Yan
Thanks everyone! Xie xie!
Thank you for your work! 

mysql-connector-java-5.1.3-rc works ok now.

Xie xie!谢谢!
[3 Oct 2007 16:42] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/34839
[3 Oct 2007 16:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/34840
[3 Oct 2007 18:59] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/34855
[5 Oct 2007 18:53] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35011
[11 Oct 2007 20:10] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35407
[11 Oct 2007 20:24] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35410
[11 Oct 2007 20:52] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35414
[19 Nov 2007 0:57] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/38019
[19 Nov 2007 2:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/38024