tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Turoff, Steve" <>
Subject [off topic] - passing a ResultSet from a servlet to a JSP
Date Tue, 29 Apr 2003 17:38:15 GMT

I've written a servlet that:

1) opens a connection to the database
2) Executes a select query and stores the data in a ResultSet
3) closes the database connection
4) Puts the ResultSet into the session
5) Forwards to a JSP page

The JSP page

1) Obtains the ResultSet from the session
2) Loops thru the ResultSet and displays the values from the datbase

I have Tomcat installations on three different machines. The code runs fine 
on two of the machines, but on the third, I get an Exeption:

org.apache.jasper.JasperException: Operation not allowed after ResultSet closed

In the stack trace, it refers to the line of my servlet : rd.forward(req, res);

After reviewing the ResultSet API, I can't figure out why the code works on 
two of the three machines. According to the API, the ResultSet is closed as 
soon as the dB connection is closed. So how can it be working? And more 
importantly, what's a better way of accomplishing this?

The machines are all configured differently:

Machine 1 - code works.
         Redhat 7.1
         Java - 1.4.0 (IBM)
         Tomcat 4.1.24
         mySQL 3.23.36

Machine 2 - code works
         Windows 2000
         Java - 1.4.0_01 (Sun)
         Tomcat 4.0.4
         mySQL - 3.23.52-nt

Machine 3 - code does not work
         Windows NT 4.0 Server
         Java - 1.4.1_02 (Sun)
         Tomcat 4.1.24
         mySQL 3.23.37

The JDBC driver on all machines is:

I simplified the problem by writing a single JSP page, which, like the above, works on machines
1 and 2, but not on 3. On machine 3, the resultset is null when I try to loop through it.

<%@ page language="java" import="java.sql.*" %>
<!-- -->

  Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost/phn?user=foo");
  Statement stmt = myConn.createStatement();
  String query = "select * from drugs where ProductName like 'a%'";
  ResultSet myResultSet = stmt.executeQuery(query);
  out.print("Closed? " + myConn.isClosed());

  if (myResultSet != null) {
    while ( {
      // specify the field name
      String name = myResultSet.getString("ProductName");
        out.print(name + "<br>");


Any help is much obliged.


Steven Turoff
Peoples Health Network
200 W. Esplanade Ave., Suite 600
Kenner, Louisiana 70065
tel: 504.461.9800 ext. 4363
fax: 461.9809


This email message and any accompanying attachments are confidential and privileged. This
information is intended solely for the addressee; access by anyone else is unauthorized. No
confidentiality or privilege is waived or lost by erroneous transmission. If you are not the
intended recipient, any forwarding, opening of attachments, disclosure, copying, distribution,
or other action, is strictly prohibited. If you have received this electronic message in error,
please delete it and any attachments and notify the sender at Peoples Health Network immediately.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message