[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index] [Home]

throw new ServletException with .jsp 0.9.10?


I have some .jsp code to display rows from a database.  It works.
However, I can't figure out how to display error messages in case
something doesn't work.  I get a compile error message when I use "throw
new ServletException" (thus I commented it out), and I don't know any
other ways to display the error using the logic I have.  Below is the
.jsp page.  It's long, but its simple.  I have included all of it just
in case there is something in it I overlooked.  The imortant code is in
the "try" section -- how do I display those error codes using gnujsp
0.9.10? (I can't get 1.0 to work).  Thanks.

<%@ import = "ADDbBean" %>
<%@ import="java.sql.*" %>
<BEAN NAME="db" TYPE="ADDbBean" INTROSPECT="yes" CREATE="yes"
SCOPE="request">
</BEAN>

<html>
<head><title>ADDbBean Test</title></head>
<body>
<%  int numColumns;
 ResultSet rs = null;
 ResultSetMetaData rsmd = null;
%>
<h1>ADDbBean Test</H1>
<CENTER>
<HR>
<BR><BR>
<TABLE BORDER="1" BGCOLOR="#cccc99" BORDERCOLOR="#003366">
<TR>

<%
 String sql = "select * from table1";
 try
 {
  db.connect();
 } catch (ClassNotFoundException e)
 {
//  throw new ServletException("Database drivers not available", e);
  System.out.println("Database drivers not available" + e);
 } catch (SQLException e)
 {
//  throw new ServletException("Database URL is wrong", e);
  System.out.println("Database URL is wrong" + e);
 }
 try
 {
  rs = db.execSQL(sql);
 } catch (SQLException e)
 {
//  throw new ServletException("Your query isn't working. " + "Do you
want to browse the database? " + "If so, leave the SQL input empty", e);

  System.out.println("Database URL is wrong" + e);
 }
 try
 {
  rsmd = rs.getMetaData();
  numColumns = rsmd.getColumnCount();

  for (int column = 1; column <= numColumns; column++)
 {
%>

<TH><%= rsmd.getColumnName(column) %></TH>

<%
 }
%>

</TR>

<%
 while (rs.next())
 {
%>

<TR>

<%
 for (int column = 1; column <= numColumns; column++)
 {
%>

<TD><%= rs.getString(column) %></TD>

<% } %>

</TR>

<% }
 rs.close();
 db.close();
 } catch (SQLException e)
 {
//  throw new ServletException("Database error.  The query worked, " +
"but the display didn't", e);
  System.out.println("Database error.  The query worked, " + "but the
display didn't" + e);
 }
%>

</TABLE>
</CENTER>

</BODY>
</HTML>


--
Ron Parker
Software Creations            http://www.scbbs.com
TradeWinds Publishing         http://www.intl-trade.com
TradePoint Los Angeles        http://www.tradepointla.org
SiteDirector Security Server  http://livepublish.scbbs.com
Civil War Online Library      http://civilwar.scbbs.com