import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; public class JDBCServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); // String name = req.getParameter("name"); out.println(""); out.println(""); out.println("Some output to the web from instantDB.

"); Connection con = null; Statement stmt = null; ResultSet rs = null; // Load the driver, get a connection, create statement, run query, and print. try { // To test with a different database, replace JDBC driver information below Class.forName("org.enhydra.instantdb.jdbc.idbDriver"); /* To test with a different database, provide appropriate connection data (e.g., database connection string, username, and password) */ // con = DriverManager.getConnection("jdbc:idb:/user/faculty/murphy/enhydraApps/simpleApp/idb/sample.prp"); con = DriverManager.getConnection("jdbc:idb:/var/www/murphy/WEB-INF/testdb/simpleApp.prp"); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT * FROM PERSON"); //rs = stmt.executeQuery("SELECT * FROM LE_TUTORIAL_DISCS"); rs.next(); out.println("Name = " + rs.getString("firstname") +" " + rs.getString("lastname")); con.close(); } catch(ClassNotFoundException e) { out.println("Couldn't load the driver: " + e.getMessage()); //System.err.println("Couldn't load the driver: " + e.getMessage()); } catch(SQLException e) { out.println("SQLException caught: " + e.getMessage()); //System.err.println("SQLException caught: " + e.getMessage()); } out.println(""); } public String getServletInfo() { return "A servlet that whom uses JDBC with InstantDB."; } }