question: public int addMissingColumns ( MPrintFormat pf ) { log . config ( pf . toString ( ) ) ; String sql = "SELECT c.AD_Column_ID, c.ColumnName " + "FROM AD_Column c " + "WHERE NOT EXISTS " + "(SELECT * " + "FROM AD_PrintFormatItem pfi" + " INNER JOIN AD_PrintFormat pf ON (pfi.AD_PrintFormat_ID=pf.AD_PrintFormat_ID) " + "WHERE pf.AD_Table_ID=c.AD_Table_ID" + " AND pfi.AD_Column_ID=c.AD_Column_ID" + " AND pfi.AD_PrintFormat_ID=?)" + " AND c.AD_Table_ID=? " + "ORDER BY c.AD_Column_ID" ; PreparedStatement pstmt = null ; ResultSet rs = null ; int counter = 0 ; try { pstmt = DB . prepareStatement ( sql , pf . get_TrxName ( ) ) ; pstmt . setInt ( 1 , pf . getAD_PrintFormat_ID ( ) ) ; pstmt . setInt ( 2 , pf . getAD_Table_ID ( ) ) ; rs = pstmt . executeQuery ( ) ; while ( rs . next ( ) ) { int AD_Column_ID = rs . getInt ( 1 ) ; String ColumnName = rs . getString ( 2 ) ; MPrintFormatItem pfi = MPrintFormatItem . createFromColumn ( pf , AD_Column_ID , 0 ) ; if ( pfi . get_ID ( ) != 0 ) log . fine ( "#" + ++ counter + " - added " + ColumnName ) ; else log . warning ( "Not added: " + ColumnName ) ; } } catch ( Exception e ) { log . log ( Level . SEVERE , sql , e ) ; } finally { DB . close ( rs , pstmt ) ; rs = null ; pstmt = null ; } if ( counter == 0 ) log . fine ( "None" ) ; else log . fine ( "Added=" + counter ) ; return counter ; }
target:  Add Missing Columns for Print Format