Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 » UltraLiteJ » Using UltraLiteJ » Developing UltraLiteJ applications » Coding examples

 

Example: Retrieving rows in an alternative order

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

package ianywhere.ultralitej.demo;
import ianywhere.ultralitej.*;

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(); ) {
                /* Can't access columns by name because no meta data */
                int inv_no = cursor.getInt( 1 /* "inv_no" */ );
                int prod_no = cursor.getInt( 2 /* "prod_no" */ );
                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 );
        }
    }
}