A servlet can create one or more Connectionobject in its init() method and reuse them in its service(),
doGet(), and doPost() methods. To demonstrate, Example 9-4 shows the phone lookup servlet rewritten
to create its Connection objects in advance. It also uses HtmlSQLResult
to display the results. Note that this servlet uses the Sybase JDBC driver.
Servlets Database Connection Using Mysql database
// File: ShowBedrock.java
/* A servlet to display the contents of the MySQL Bedrock database */
public class ShowBedrock extends HttpServlet
{
public String getServletInfo()
{
return "Servlet connects to MySQL database and displays result of a SELECT";
}