<% // Written by Brad Simonin. // This Java Server Page writes information from an Access 97 database // to an HTML table using the JDBC:ODBC Bridge. %> <%@ page language="java" import="java.sql.*,java.io.*, java.util.*" %> <% response.setContentType("text/html"); %> View Comments <% String strID = request.getParameter("ID"); strID = strID.trim(); String SqlString; String Name = null; String Comments = null; SqlString = "SELECT Name, Comments FROM Brads_GuestBook" + " WHERE GuestBook_Id = " + strID + ";"; try { Connection con = null; con = null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbc:odbc:Brad2000"; // Brad is the name of my ODBC DSN con = DriverManager.getConnection(url); Statement stmt; stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(SqlString); while(rs.next()) { Name = rs.getString("Name"); Comments = rs.getString("Comments"); if (Name == null) Name = ""; if (Comments == null) Comments = ""; } stmt.close(); con.close(); } catch(SQLException SQL_ex) { out.println("SQLException: " + SQL_ex.getMessage()); } catch(ClassNotFoundException Class_ex) { out.println("ClassException: " + Class_ex.getMessage()); } %>

Comments from <%= Name %>:

<%= Comments %>