• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 840
  • Last Modified:

Printout many Resultset on one page

Hi there,
I want to print out many resultset on the one webpage, tried this but wont work comment out parts:
Any ideas, where I am going wrong?
    Statement  = connection.createStatement();
ResultSet rs56= Statement.executeQuery("SELECT count(*)as count FROM Test_Results ");

/* ResultSet rs59= Statement.executeQuery("SELECT avg(Total_MM) as avgMM FROM Test_Results");
*/

%>
<table width="80%" height="64"  border="0" cellpadding="0" cellspacing="0">   <tr>
<%while (rs56.next ()){%>The Number of Fields in the Test_Results Table: <%=rs56.getString("count")%>       <%}%>   </table>

<table width="80%" height="64"  border="0" cellpadding="0" cellspacing="0">
  <tr>
     <% /*while (rs59.next ()){%>The Number of Fields in the Test_Results Table: <%=rs59.getString("avgMM")%>     <%} */%>  
  </table>

This works but when I take off the comments, I get a blank page but I have run the query in the db and the average shoudl come to be 52.1538.
Regards.
acslater
0
acslater
Asked:
acslater
  • 3
  • 3
1 Solution
 
acslaterAuthor Commented:
They work separetely why can't I do them together... any comments
0
 
searlasCommented:
From:
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html

By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.


In your case, you can get away with just one Statement, but you have to finish using the ResultSet from the first query before calling executeQuery for rs59.
0
 
acslaterAuthor Commented:
>>In your case, you can get away with just one Statement, but you have to finish using the ResultSet from the first query before calling executeQuery for rs59.

Would that mean I need to close connection and reopen connection for next one?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
searlasCommented:
No, you just need to move the rs59 call into the second set of <% %> tags...

BTW... your tables are missing <td> elements

<%
// Java code usually uses lower-case for variables...
Statement statement = connection.createStatement();
ResultSet rs56= Statement.executeQuery("SELECT count(*)as count FROM Test_Results ");
%>
<table width="80%" height="64"  border="0" cellpadding="0" cellspacing="0">   <tr>
<%while (rs56.next ()){%>The Number of Fields in the Test_Results Table: <%=rs56.getString("count")%>       <%}%>   </table>

<table width="80%" height="64"  border="0" cellpadding="0" cellspacing="0">
  <tr>
<%
ResultSet rs59= Statement.executeQuery("SELECT avg(Total_MM) as avgMM FROM Test_Results");
while (rs59.next ()){%>The Number of Fields in the Test_Results Table: <%=rs59.getString("avgMM")%>     <%} %>  
  </table>
0
 
acslaterAuthor Commented:
>> your tables are missing <td> elements
Thanks..

This is the code I have but it still not working... was blank but now: getting errors:
-------------------
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
    [javac] Compiling 1 source file
      at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
      at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
      at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:353)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370)
...

-----------------
<body>
<div align="center">
  <%
Statement      Statement = null;
ResultSet      resultset = null;
ResultSetMetaData rsmd = null;
Connection      connection = null;

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
connection = DriverManager.getConnection("jdbc:mysql://????? %>

<% // Java code usually uses lower-case for variables...
Statement statement = connection.createStatement();
ResultSet rs56= Statement.executeQuery("SELECT avg(Total_AIC) as avgAIC FROM Test_Results ");

<table width="80%" height="64"  border="0" cellpadding="0" cellspacing="0">  
 
<%while (rs56.next ()){%> <td>The Average Results for Applied Industrial Computing is:</td> <td> <%=rs56.getString("avgAIC")%>   </td>     <%}%>

<% ResultSet rs59= Statement.executeQuery("SELECT avg(Total_MM) as avgMM FROM Test_Results");
while (rs59.next ()){%><td>The Results for MultiMedia: </td><td><%=rs59.getString("avgMM")%>    </td> <%} %>  
</table>
<%    connection.close();
%>
</div>
</body>
</html>
0
 
searlasCommented:
Maybe I shouldn't have bothered trying to make you switch case between Statement and statement.

Take a look at your variable declrations and decide which ones you're actually using... and remove the others.  (looks like you're using assigning the createStatememt() value to 'statement' but then assume you can use Statement.executeQuery....  which is null.)

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now