Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-344

Method createDynaProperty of JDBCDynaClass should first look for column label instead of column name in ResultSetMetadata object..

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.0-BETA
    • 1.8.1
    • DynaBean
    • None

    Description

      Method createDynaProperty( ResultSetMetaData metadata, int i) of class JDBCDynaClass should read column label instead of column name from ResultSetMetadata object.

      For example..
      If query is something like 'select user_id as userId, user_name as userName....' than columName variable should have the value userId instead of user_id

      Fix is ..

      Original

      JDBCDynaClass.java
      protected DynaProperty createDynaProperty(
                                          ResultSetMetaData metadata,
                                          int i)
                                          throws SQLException {
      //This is reading ColumnName but not ColumnLabel which returns value 'user_id' ..not 'userId' 
      String columnName = metadata.getColumnName(i); 
      ...
      ...
      ...
      }
      

      It should be like following

      JDBCDynaClass.java
      protected DynaProperty createDynaProperty(
                                          ResultSetMetaData metadata,
                                          int i)
                                          throws SQLException {
       //First read ColumnLabel ..which sould be 'userId' in our case
       String columnName = metadata.getColumnLabel(i);  
      
       // If ColumnLabel is 'null' or 'empty' read ColumnName...
       if(columnName == null || columnName.trim().equals(""))  {  
           columnName = metadata.getColumnName(i);
       }
      ...
      ...
      ...
      

      Let me know if this is not how it suppose to be or I am missing something here.

      Thanks,
      Viral Patel

      Attachments

        Issue Links

          Activity

            People

              niallp Niall Pemberton
              viralpatel79 Viral
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 5h
                  5h
                  Remaining:
                  Remaining Estimate - 5h
                  5h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified