I am trying to retrieve data from table in two times.
In first query I am displaying all data available in table.
Now I want to count the no. Of rows available in the same table by using select count(*)from table-name type query.
How can I retrieve records of same table by firing these two queries in single jsp page :
Please Tell me how to execute to query un single jsp page.
Here is an page where i able to fired the single query to display the table:

    Document   : fillquestion
    Created on : Jul 18, 2008, 10:07:43 AM
    Author     : user1

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language ="java" %>
<%@ page import="java.sql.*, javax.sql.*, javax.naming.*,java.io.*,java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <form name="fill-ok" action="fill-question-ok.jsp" method="POST">
        <table width="50%" border="1" borderColor="#000066" cellspacing="0" cellpadding="5" align="center">
		<td colspan="8" align="middle" class="StripColor">
			<font class="FontGeneralBoldWhite">Fill Up the Question</font>
        String ID=request.getParameter("id"); 
        String EVENTID=request.getParameter("even");
        Connection connection = null;
        Statement st = null;
        ResultSet rs = null;
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mynewdatabase","root", "root123");
           try {
            rs = st.executeQuery("SELECT * FROM questionbank where questionid='"+ID+"'LIMIT 5");
         while ( rs.next() )

             <input type="hidden" name="Event" value="<%=request.getParameter("event")%>"/>
             <input type="hidden" name="ID" value="<%=request.getParameter("id")%>"/>
             <input type="hidden" name="QseriNO" value="<%=rs.getString("qserialno")%>"/>
                 //<td><input type="hidden" name="QserialNO" value="<%=request.getParameter("Qserialno")%>"></td>
                <td><b>A:</b><input type="radio" name="answer<%=rs.getString("qserialno")%>" value="A" /><%=rs.getString("OptionA")%></td>           
                <td><B>B:</B><input type="radio" name="answer<%=rs.getString("qserialno")%>" value="B" /><%=rs.getString("OptionB")%></td>
                <td><B>C:</B><input type="radio" name="answer<%=rs.getString("qserialno")%>" value="C" /><%=rs.getString("OptionC")%></td> 
                <td><B>D:</B><input type="radio" name="answer<%=rs.getString("qserialno")%>" value="D" /><%=rs.getString("OptionD")%></td>                 	

                       }   finally
                           if (rs != null)
                               rs = null;
                           if (st != null)
                               st = null;

                <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="SUBMIT" name="submit" /></TD>
                <td><input type="reset" value="RESET" name="reset" /></td>

Thanks in advance

Modify query like this.

SELECT *,count(questionid) as count FROM questionbank where questionid='"+ID group by questionid

If you want that count to be executed as different query, use different result set.

The count will give the answer

For more code snippets


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.