Java Reference
In-Depth Information
L ISTING 22.7
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 query.”);
}
// Get a database connection from TRADER_POOL
ConnectionPool pool =
(ConnectionPool)context.getAttribute(“TRADER_POOL”);
Connection con = pool.getConnection();
try {
if ( con != null ) {
// Get the stock information from the database
Statement statement = con.createStatement();
StringBuffer query =
new StringBuffer(“SELECT * FROM STOCKS”);
query.append(“ WHERE SYMBOL = \'” + symbol + “\'”);
System.err.println(“Executing : “ + query.toString());
ResultSet rs =
statement.executeQuery(query.toString());
System.err.println(“Executed : “ + query.toString());
if ( rs.next() ) {
// Add the stock attribute to the request
request.setAttribute(“symbol”,
rs.getString(“symbol”));
Search WWH ::




Custom Search