Java Reference
In-Depth Information
L ISTING 22.7
Continued
request.setAttribute(“price”, rs.getString(“price”));
request.setAttribute(“bid”, rs.getString(“bid”));
request.setAttribute(“ask”, rs.getString(“ask”));
}
}
}
finally {
// release the database connection back into the pool
pool.releaseConnection(con);
22
}
}
}
The Buy Service
The Buy class is also an implementation of the Service interface. Its execute() method starts
its execution when a user selects the Buy radio button and fills in symbol and price informa-
tion from the tradeform.jsp page. It then gets the symbol and price from the request and per-
forms a select statement on the stocks table, returning a ResultSet containing the stock's
attributes. It then checks for an existing ask price that is either less than or equal to the submit-
ted bid price. If there is a satisfying ask price, the current price is set to the bid price and the
ask price is reset to 0. Otherwise the new bid is updated. The source for the Buy service is in
Listing 22.8.
L ISTING 22.8
Buy.java
import java.sql.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletContext;
import Service;
import ConnectionPool.ConnectionPool;
public class Buy implements Service {
public Buy() {
}
 
Search WWH ::




Custom Search