Example: Aggregation and grouping

This example demonstrates UltraLiteJ support for the aggregation of results.

package ianywhere.ultralitej.demo;
import ianywhere.ultralitej.*;
/** Create a sales report to illustrate aggregation support.
 */
public class SalesReport
{
    /** Mainline.
     * @param args program arguments (not used)
     */
    public static void main( String[] args )
    {
        try {
            Configuration config = DatabaseManager.createConfigurationFile( "Sales.ulj" );
            Connection conn = DatabaseManager.connect( config );
            PreparedStatement stmt = conn.prepareStatement(
                "SELECT inv_no, SUM( quantity * price ) AS total"
                + " FROM InvoiceItem"
                + " GROUP BY inv_no ORDER BY inv_no"
            );
            ResultSet agg_cursor = stmt.executeQuery();
            for( ; agg_cursor.next(); ) {
                int inv_no = agg_cursor.getInt( 1 /* "inv_no" */ );
                String total = agg_cursor.getString( 2 /* "total" */ );
                Demo.display( Integer.toString( inv_no ) + ' ' + total );
            }
            Demo.display( "SalesReport completed successfully" );
        } catch( ULjException exc ) {
            Demo.displayException( exc );
        }
    }
}