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
acslaterAsked:
Who is Participating?
 
searlasConnect With a Mentor Commented:
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
 
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.