Java Reference
In-Depth Information
L ISTING 22.8
Continued
if ( rs.next() ) {
int ask = rs.getInt(“ask”);
int bid = ((new Integer(price)).intValue());
rs.close();
StringBuffer update =
new StringBuffer(“UPDATE STOCKS”);
22
// Check to see if there is an
// open ASK satisfying our BID
if ( bid >= ask && ask != 0 ) {
// if there is, then set the
// price to the bid price
// and reset the ask to 0
update.append(“ SET PRICE = “ + price);
update.append(“, ASK = 0”);
update.append(“ WHERE SYMBOL = '“ + symbol + “'“);
}
else {
// if there is no match set the bid price
// to the offered price
update.append(“ SET BID = “ + price);
update.append(“ WHERE SYMBOL = '“ + symbol + “'“);
}
System.err.println(“Executing : “ +
update.toString());
statement.executeUpdate(update.toString());
}
}
}
finally {
pool.releaseConnection(con);
}
}
}
 
Search WWH ::




Custom Search