Java Reference
In-Depth Information
L ISTING 22.8
Continued
/*
implemented method from Service interface
*/
public void execute(HttpServletRequest request,
HttpServletResponse response,
ServletContext context) throws Exception {
// Get the symbol from the request
String symbol = request.getParameter(“symbol”);
if ( symbol == null ) {
throw
new Exception(“You must enter a stock symbol to purchase.”);
}
// 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.”);
}
// Get a database connection from TRADER_POOL
ConnectionPool pool =
(ConnectionPool)context.getAttribute(“TRADER_POOL”);
Connection con = pool.getConnection();
try {
if ( con != null ) {
Statement statement = con.createStatement();
// Get the stocks attributes
StringBuffer query =
new StringBuffer(“SELECT ASK FROM STOCKS”);
query.append(“ WHERE SYMBOL = \'” + symbol + “\'”);
ResultSet rs =
statement.executeQuery(query.toString());
Search WWH ::




Custom Search