import java.sql.*; import java.io.*; import sqlj.runtime.ref.DefaultContext; #sql iterator QuotesIter2(String symbol, float price, float change); class StockQuotesSqljRsetMeta { public static void main (String arg[]) throws Exception { QuotesIter2 quotes; // Connect to the Database DefaultContext.setDefaultContext(new DefaultContext(Examples.getConnection())); // Use first command line arg as customer id int id = Integer.parseInt( arg[0] ); #sql quotes = { SELECT q.symbol as "Symbol", q.price as "Price", q.change as "Change" FROM quotes q, portfolio_stocks ps WHERE q.symbol = ps.symbol AND ps.owner = :id }; PrintWriter out = new PrintWriter(System.out); XMLForResultSet.print( quotes.getResultSet(),"Quotes","Quote",out); out.close(); quotes.close(); } } |