<% // 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"); %> Brad Simonin's GuestBook <% String SqlString; String HTMLString; int ThePos1; int ThePos2; SqlString = "SELECT GuestBook_Id, Name, Company_Occupation, City, " + "State, E_Mail, Web_Page FROM Brads_GuestBook ORDER BY Time_Stamp Desc"; %> <% 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()) { ThePos1 = -1; ThePos2 = -1; int Id = rs.getInt("GuestBook_Id"); String Name = rs.getString("Name"); String Occupation = rs.getString("Company_Occupation"); String City = rs.getString("City"); String State = rs.getString("State"); String E_Mail = rs.getString("E_Mail"); String WebPage = rs.getString("Web_Page"); if (Name == null) Name = ""; if (Occupation == null) Occupation = ""; if (City == null) City = ""; if (State == null) State = ""; if (E_Mail == null) E_Mail = ""; if (WebPage == null) WebPage = ""; if (WebPage.indexOf((String)"#") != -1) { ThePos1 = WebPage.indexOf((String)"#",0); ThePos2 = WebPage.indexOf((String)"#",ThePos1 + 1); WebPage = WebPage.substring(ThePos1 + 1,ThePos2); } WebPage = WebPage.trim(); %> <% } stmt.close(); con.close(); } catch(SQLException SQL_ex) { out.println("SQLException: " + SQL_ex.getMessage()); } catch(ClassNotFoundException Class_ex) { out.println("ClassException: " + Class_ex.getMessage()); } %>
Brad Simonin's GuestBook
Name Occupation City State E-Mail Web Page View Comments
<%= Name %>
<%= Occupation %>
<%= City %>
<%= State %>
<%= E_Mail %>
<%= WebPage %>
<% out.println("

To view the source code of this JavaServer Page click on the " + "following hyperlink: " + "ViewGuestBook.jsp

"); %>