TextNullable title3 = null;
int numCustomers = 0;
IntegerData numStocks = null;
double totalValue = 0;
DBConnectionManager dBConnection = DBConnectionManager.getInstance("DBConnection");
// -- =============== Original SQL ===============
// select
// 'Customers',
// count(distinct CustomerName),
// 'Stocks',
// count(distinct StockName),
// 'Total value',
// sum(Price*Quantity)
// into
// :title1,
// :numCustomers,
// :title2,
// :numStocks,
// :title3,
// :totalValue
// from Holding
// on session DBConnection
// -- ============================================
String qq_SQL = "select " +
"'Customers', " +
"count(distinct CustomerName), " +
"'Stocks', " +
"count(distinct StockName), " +
"'Total value', " +
"sum(Price*Quantity) " +
"from Holding ";
final ParameterHolder qqh_title1 = new ParameterHolder(title1);
final ParameterHolder qqh_numCustomers = new ParameterHolder(numCustomers);
final ParameterHolder qqh_title2 = new ParameterHolder(title2);
final ParameterHolder qqh_numStocks = new ParameterHolder(numStocks);
final ParameterHolder qqh_title3 = new ParameterHolder(title3);
final ParameterHolder qqh_totalValue = new ParameterHolder(totalValue);
RowCountCallbackHandler qq_RowCounter = new RowCountCallbackHandler() {
protected void processRow(ResultSet pResultSet, int pRow) throws SQLException {
if (pRow >= 1) {
throw new IncorrectResultSizeDataAccessException(1, pRow+1);
}
ResultSetHelper helper = new ResultSetHelper(pResultSet);
qqh_title1.setObject(helper.getString(1));
qqh_numCustomers.setInt(helper.getInt(2));
qqh_title2.setObject(helper.getTextData(3));
qqh_numStocks.setObject(helper.getIntegerData(4));
qqh_title3.setObject(helper.getTextNullable(5));
qqh_totalValue.setDouble(helper.getDouble(6));
}
};
dBConnection.getTemplate().query(qq_SQL, qq_RowCounter);
title1 = (String)qqh_title1.getObject();
numCustomers = qqh_numCustomers.getInt();
title2 = (TextData)qqh_title2.getObject();
numStocks = (IntegerData)qqh_numStocks.getObject();
title3 = (TextNullable)qqh_title3.getObject();