| Bug #21596 | column aliases ignored in ResultSetMetaData | ||
|---|---|---|---|
| Submitted: | 11 Aug 2006 19:11 | Modified: | 14 Aug 2006 1:35 |
| Reporter: | Peter Brown | Email Updates: | |
| Status: | Duplicate | Impact on me: | |
| Category: | Connector / J | Severity: | S2 (Serious) |
| Version: | 5.0.2-beta, 5.0.3 | OS: | Windows (Windows XP) |
| Assigned to: | CPU Architecture: | Any | |
[14 Aug 2006 1:35]
Mark Matthews
Duplicate of BUG#21379. This is a change required for JDBC-compliance. RSMD.getColumnName() is required to return the actual column name. Aliases are returned via RSMD.getColumnLabel(). If you want the older non-compliant behavior from Connector/J 3.1, use the "useOldAliasMetadataBehavior" configuration parameter present in the 5.0 nightly builds, and set it to "true".

Description: the result set meta data for a query like SELECT id as value, description as text from foo returns 'id' and 'description' as the column names instead of 'value' and 'text' NOTES: -above bug occurs with version 5.0.3 + mysql Ver 14.12 Distrib 5.0.22, for Win32 (ia32) + Java 1.5.0_07 -works correctly with version 5.0.3 + mysql Ver 12.22 Distrib 4.0.16, for Win95/Win98 (i32) + Java 1.4.2_02 -works correctly with version 3.0.9 + mysql 4/java 1.4, or mysql 5/java 1.5 How to repeat: import java.sql.*; public class JDBCMetaDataTest { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tester", "usr", "pwd"); Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("select id as value, description as text from foo"); ResultSetMetaData rsmd = rs.getMetaData(); for ( int i = 1; i <= rsmd.getColumnCount(); i++) { System.out.println(rsmd.getColumnName(i)); } } catch (Exception ex) { System.out.println(ex.toString()); } } } C:\path>javac JDBCMetaDataTest.java C:\path>java -classpath mysql-connector-java-3.0.9-stable-bin.jar;. JDBCMetaDataTest value text C:\path>java -classpath mysql-connector-java-5.0.3-bin.jar;. JDBCMetaDataTest id description