FileDocCategorySizeDatePackage
DBPhoneLookupReuse.javaAPI DocExample1428Tue Jan 25 10:45:14 GMT 2000None

DBPhoneLookupReuse

public class DBPhoneLookupReuse extends HttpServlet

Fields Summary
private Connection
con
Constructors Summary
Methods Summary
public voiddestroy()

    // Clean up.
    try {
      if (con != null) con.close();
    }
    catch (SQLException ignored) { }
  
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

    res.setContentType("text/html");
    PrintWriter out = res.getWriter(); 

    out.println("<HTML><HEAD><TITLE>Phonebook</TITLE></HEAD>");
    out.println("<BODY>");

    HtmlSQLResult result = 
      new HtmlSQLResult("SELECT NAME, PHONE FROM EMPLOYEES", con);
     
    // Display the resulting output
    out.println("<H2>Employees:</H2>");
    out.println(result);
    out.println("</BODY></HTML>");
  
public voidinit(javax.servlet.ServletConfig config)


        
    super.init(config);
    try {
      // Load (and therefore register) the Sybase driver
      Class.forName("com.sybase.jdbc.SybDriver");
      con = DriverManager.getConnection(
        "jdbc:sybase:Tds:dbhost:7678", "user", "passwd");
    }
    catch (ClassNotFoundException e) { 
      throw new UnavailableException(this, "Couldn't load database driver");
    }    
    catch (SQLException e) { 
      throw new UnavailableException(this, "Couldn't get db connection");
    }