public int getIndex ( String name ) throws SQLException { if ( name == null ) { throw new SQLException ( "Column name cannot be null" ) ; } String lowerName = name . toLowerCase ( Locale . ROOT ) ; // The specs in JDBC 4.0 specify that ResultSet.findColumn and // ResultSet.getXXX(String name) should use column alias (AS in the query). If label is not found, we use // original table name. if ( aliasMap == null ) { aliasMap = new HashMap <> ( ) ; int counter = 0 ; for ( ColumnInformation ci : columnInfo ) { String columnAlias = ci . getName ( ) ; if ( columnAlias != null ) { columnAlias = columnAlias . toLowerCase ( Locale . ROOT ) ; aliasMap . putIfAbsent ( columnAlias , counter ) ; String tableName = ci . getTable ( ) ; if ( tableName != null ) { aliasMap . putIfAbsent ( tableName . toLowerCase ( Locale . ROOT ) + "." + columnAlias , counter ) ; } } counter ++ ; } } Integer res = aliasMap . get ( lowerName ) ; if ( res != null ) { return res ; } if ( originalMap == null ) { originalMap = new HashMap <> ( ) ; int counter = 0 ; for ( ColumnInformation ci : columnInfo ) { String columnRealName = ci . getOriginalName ( ) ; if ( columnRealName != null ) { columnRealName = columnRealName . toLowerCase ( Locale . ROOT ) ; originalMap . putIfAbsent ( columnRealName , counter ) ; String tableName = ci . getOriginalTable ( ) ; if ( tableName != null ) { originalMap . putIfAbsent ( tableName . toLowerCase ( Locale . ROOT ) + "." + columnRealName , counter ) ; } } counter ++ ; } } res = originalMap . get ( lowerName ) ; if ( res == null ) { throw ExceptionMapper . get ( "No such column: " + name , "42S22" , 1054 , null , false ) ; } return res ; }
Get column index by name .