<%@ page import = "java.sql.*" %> <% // Parameter values are retrieved using getParameter. String reqType = request.getParameter("type"); if (reqType == null) reqType = "search"; // Choose which type of page to display. if (reqType.equals("search")) { out.println("

Welcome to the FMB

"); // Use the shared connection. Connection db = getDB(); // A statement is analogous to a command line. Statement stmt = db.createStatement(); // A result set provides a one-time pass over the result of some query. // This query determines how many names (not synonyms) are in the database. ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM names WHERE isSynonym = 0;"); // The cursor starts before the first record. // .next() returns false once the cursor falls off the end. rs.next(); out.println("

There are " + rs.getString(1) + " terms in the FMA.

"); // Statements consume database resources, so they need to be closed. stmt.close(); } else { out.println("

Unknown request type: " + reqType + "

"); } %> <%! private static Connection db = null; static { try { // Load the postgres driver. Class.forName("org.postgresql.Driver"); // Establish a shared connection to the class database. db = DriverManager.getConnection("jdbc:postgresql://cubist.cs.washington.edu/cse544", "sample", "cse544"); } catch (Exception e) {} } public Connection getDB() { return db; } %>