Databases Reference
In-Depth Information
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/**
* QuoteSearch is a Java servlet created to allow a client to search the
* database for a keyword.
* Created October 15, 1998.
* For more information, please see <a href="http://jserv.java.sun.com/
* products/java-server/servlets/index.html">the Servlet SDK.</a>
* @author Jonathan S. Held
* @version 1.0
*/
public class QuoteSearch extends HttpServlet
{
static java.sql.Connection con;
static java.sql.Statement stmt;
static final java.lang.String url = "jdbc:odbc:Quotation_DB";
static final int INITIAL_SIZE = 20;
/**
* init() - Servlet method invoked only once by the servletrunner
* utility; this is a good method to include code for resource-
* intensive operations, such as connecting to a database
* @param response ServletConfig object
* @return void
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url, "", "");
stmt = con.createStatement();
}
catch (java.lang.ClassNotFoundException e1) { }
catch (java.sql.SQLException e2){ }
}//end init()
/**
* doPost() - Overridden from HttpServlet to handle POST operations.
* @param request HttpServlet request object encapsulating
* communication from the client
* @param response HttpServletResponse object encapsulating means of
* communicating from the server back to the client
* @return void
* @exception ServletException handled by the superclass
* This method implements a GET operation called from an HTML form's
* ACTION URL. HTML is sent back to the client via the response
* object.
*/
public void doPost (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
java.lang.String keyword = request.getParameter("keyword");
if (keyword.equals(""))
return;
else goFindIt(keyword, response);
}
Exhibit 34-12. The QuoteSearch Servlet code.
Search WWH ::




Custom Search