Example: Retrieving rows in an alternative order

This example demonstrates UltraLiteJ support for processing rows in an alternate order.

 To run the SortTransactions.java example
  1. Change to the following directory: samples-dir\UltraLiteJ.

    For information about the default location of samples-dir, see Samples directory.

  2. Run the CreateSales example:

    rundemo CreateSales

    See Example: Creating a sales database.

  3. Run the following command (the command is case sensitive):

    rundemo SortTransactions


// *****************************************************
// Copyright (c) 2006-2010 iAnywhere Solutions, Inc.
// Portions copyright (c) 2006-2010 Sybase, Inc.
// All rights reserved. All unpublished rights reserved.
// *****************************************************
// This sample code is provided AS IS, without warranty or liability
// of any kind.
//
// You may use, reproduce, modify and distribute this sample code
// without limitation, on the condition that you retain the foregoing
// copyright notice and disclaimer as to the original iAnywhere code.
//
// *********************************************************************
package com.ianywhere.ultralitej.demo;
import com.ianywhere.ultralitej12.*;

/** Illustrate use of SortCursor to produce a
 *  stream of rows in a different order.
 */
public class SortTransactions
{
    /** 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, prod_no, quantity FROM InvoiceItem"
		    + " ORDER BY prod_no"
		);
	    ResultSet cursor = stmt.executeQuery();
	    for( ; cursor.next(); ) {
		int inv_no = cursor.getInt( 1 /* "inv_no" */ );
		int prod_no = cursor.getInt( "prod_no" ); //access by name
		int quantity = cursor.getInt( 3 /* "quantity" */ );
		Demo.display( Integer.toString( prod_no ) + ' '
			    + Integer.toString( inv_no ) + ' '
			    + Integer.toString( quantity ) );
	    }
	    conn.release();
	    Demo.display( "SortTransactions completed successfully" );
	} catch( ULjException exc ) {
	    Demo.displayException( exc );
	}
    }
}