You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Turoff, Steve" <St...@tenethealth.com> on 2003/04/29 19:38:15 UTC
[off topic] - passing a ResultSet from a servlet to a JSP
Greetings,
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: org.gjt.mm.mysql.Driver
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.
<html>
<head>
</head>
<%@ page language="java" import="java.sql.*" %>
<body>
<!-- org.gjt.mm.mysql.Driver -->
<%
Class.forName("org.gjt.mm.mysql.Driver");
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);
stmt.close();
myConn.close();
out.print("Closed? " + myConn.isClosed());
%>
<p>hello</p>
<%
if (myResultSet != null) {
while (myResultSet.next()) {
// specify the field name
String name = myResultSet.getString("ProductName");
out.print(name + "<br>");
}
}
%>
<p>goodbye</p>
</body>
</html>
Any help is much obliged.
Steve
Steven Turoff
Peoples Health Network
200 W. Esplanade Ave., Suite 600
Kenner, Louisiana 70065
tel: 504.461.9800 ext. 4363
fax: 461.9809
CONFIDENTIAL HEALTH INFORMATION
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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org