Bug #18540 MetaData getColumnName() method don't work in some case
Submitted: 27 Mar 2006 13:31 Modified: 28 Mar 2006 18:10
Reporter: kadir doğan Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5 beta OS:Windows (XP)
Assigned to: CPU Architecture:Any

[27 Mar 2006 13:31] kadir doğan
Description:
If you get MetaData from a result set reulting of a SELECT query with aliases (select ... as alias) the getColumName() method will return null.

In connector 3.18 with the same code this work fine (don't return null), so without testing more I suggest that this is a bug.

How to repeat:
m_PreparedStatement = m_Connection.prepareStatement("SELECT something AS other_name from something_else");
m_PreparedStatement.execute();
ResultSet rs = m_PreparedStatement.getResultSet();
ResultSetMetaData md = rs.getMetaData();
String s = md.getColumnName(i + 1);
[28 Mar 2006 18:10] Tonci Grgin
Thanks for your bug report. I can not reproduce it.
WinXP SP2, JDK 1.6, MySQL connector java 5.0.0 beta, 5.1.7-beta-nt-max-log:

   public void testPreparedStatement1() throws Exception { 
       PreparedStatement st = con.prepareStatement("select FOO AS Col1 from booleanbug"); 
       System.out.println("-----------------------------------");
       System.out.println("Prepared stmt");
       testResult(st.executeQuery()); 
   } 
   
   public void testStatement1() throws Exception { 
       Statement st = con.createStatement(); 
       System.out.println("Stmt");
       testResult(st.executeQuery("select FOO AS Col1 from booleanbug")); 
   } 
   
   private void testResult(ResultSet rs) throws Exception { 
       rs.next(); 

       ResultSetMetaData md = rs.getMetaData();
       System.out.println("ColName: " + md.getColumnName(1));       
       System.out.println("ColAlias: " + md.getColumnLabel(1));       

       System.out.println("ColVal: " + rs.getString(1));
       
   }    

run:
Stmt
ColName: FOO
ColAlias: Col1
ColVal: foo
-----------------------------------
Prepared stmt
ColName: FOO
ColAlias: Col1
ColVal: foo