本示例演示 UltraLiteJ 对结果集合的支持。
转到以下目录:samples-dir\UltraLiteJ。
有关 samples-dir 缺省位置的信息,请参见示例目录。
运行 CreateSales 示例:
rundemo CreateSales |
请参见示例:创建销售数据库。
运行以下命令(此命令区分大小写):
rundemo SalesReport |
// ***************************************************** // 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.*; /** 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( "total" ); // access by name Demo.display( Integer.toString( inv_no ) + ' ' + total ); } Demo.display( "SalesReport completed successfully" ); } catch( ULjException exc ) { Demo.displayException( exc ); } } } |
![]() |
使用DocCommentXchange 讨论此页。
|
版权 © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |