question: public void testResultSetMetadate ( ) throws Exception { final int rows = 1 ; final int tables = 10 ; final int columns = 100 ; Statement st = con . createStatement ( ) ; StringBuilder sb = new StringBuilder ( ) ; try { for ( int t = 0 ; t < tables ; t ++ ) { sb . setLength ( 0 ) ; sb . append ( "create table #TABLE" ) ; sb . append ( t ) ; sb . append ( "(ID int primary key" ) ; for ( int c = 0 ; c < columns ; c ++ ) { sb . append ( ",COLUMN" ) ; sb . append ( c ) ; sb . append ( " int" ) ; } sb . append ( ")" ) ; st . execute ( sb . toString ( ) ) ; } for ( int t = 0 ; t < tables ; t ++ ) { sb . setLength ( 0 ) ; sb . append ( "insert into #TABLE" ) ; sb . append ( t ) ; sb . append ( " values(?" ) ; for ( int c = 0 ; c < columns ; c ++ ) { sb . append ( ",?" ) ; } sb . append ( ")" ) ; PreparedStatement pst = con . prepareStatement ( sb . toString ( ) ) ; for ( int r = 0 ; r < rows ; r ++ ) { for ( int c = 0 ; c <= columns ; c ++ ) { pst . setInt ( c + 1 , r ) ; } pst . addBatch ( ) ; } Assert . assertEquals ( rows , pst . executeBatch ( ) . length ) ; } sb . setLength ( 0 ) ; sb . append ( "select * from " ) ; for ( int t = 0 ; t < tables ; t ++ ) { sb . append ( t > 0 ? "," : "" ) ; sb . append ( "#TABLE" ) ; sb . append ( t ) ; } if ( tables > 1 ) { sb . append ( " where " ) ; for ( int t = 1 ; t < tables ; t ++ ) { sb . append ( t > 1 ? " and " : "" ) ; sb . append ( "#TABLE" ) ; sb . append ( t ) ; sb . append ( ".id=" ) ; sb . append ( "#TABLE" ) ; sb . append ( t - 1 ) ; sb . append ( ".id" ) ; } } ResultSet rs = st . executeQuery ( sb . toString ( ) ) ; ResultSetMetaData rsmd = rs . getMetaData ( ) ; int toalColumns = rsmd . getColumnCount ( ) ; Assert . assertEquals ( tables * ( columns + 1 ) , toalColumns ) ; for ( int r = 0 ; r < rows ; r ++ ) { assertTrue ( rs . next ( ) ) ; } int index = 0 ; for ( int t = 0 ; t < tables ; t ++ ) { for ( int c = 1 ; c <= columns + 1 ; c ++ ) { index ++ ; Assert . assertEquals ( c > 1 ? ( "COLUMN" + ( c - 2 ) ) : "ID" , rsmd . getColumnName ( index ) ) ; Assert . assertEquals ( Types . INTEGER , rsmd . getColumnType ( index ) ) ; Assert . assertEquals ( "#TABLE" + t , rsmd . getTableName ( index ) ) ; } } } finally { for ( int t = 0 ; t < tables ; t ++ ) { dropTable ( "#TABLE" + t ) ; } } }
target:  Test for bug [1833720], invalid table names for large result sets.