Java Reference
In-Depth Information
L ISTING 22.9
Continued
// Get the price from the request
String price = request.getParameter(“price”);
if ( price == null ) {
throw
new Exception(“You must enter a stock price to purchase.”);
}
22
// Get a database connection from TRADER_POOL
ConnectionPool pool =
(ConnectionPool)context.getAttribute(“TRADER_POOL”);
Connection con = pool.getConnection();
try {
if ( con != null ) {
// Check to see if there is an
// open BID satisfying our ASK
Statement statement = con.createStatement();
StringBuffer query =
new StringBuffer(“SELECT BID FROM STOCKS”);
query.append(“ WHERE SYMBOL = \'” + symbol + “\'”);
// Get the stocks attributes
ResultSet rs =
statement.executeQuery(query.toString());
if ( rs.next() ) {
int bid = rs.getInt(“bid”);
int ask = ((new Integer(price)).intValue());
rs.close();
StringBuffer update =
new StringBuffer(“UPDATE STOCKS”);
// Check to see if there is
// an open BID satisfying our ASK
if ( bid >= ask && ask != 0 ) {
 
Search WWH ::




Custom Search