User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 426,013 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,607 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 613 | Replies: 1 | Solved
Reply
Join Date: Jun 2008
Posts: 37
Reputation: guravharsha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

How to retrive data two times from database in single jsp page.

  #1  
Jul 22nd, 2008
Hi,
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"
   "http://www.w3.org/TR/html4/loose.dtd">

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

	    <tr>
             <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><%=rs.getString("qserialno")%>:&nbsp;&nbsp;<b>Question:</b>
               <%=rs.getString("questionname")%>
		</td>
                </tr>
                <tr>
                 //<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>                 	
                </tr>             
		        <%
                           }

                       }   finally
                       {
                           if (rs != null)
                           {
                               rs.close();
                               rs = null;
                           }
                           if (st != null)
                           {
                               st.close();
                               st = null;
                           }

                       }
                      
                   %>
    </table>
    <tr>
                <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>
                    
	       </tr>
   </form>
   </body>
   </html>

Thanks in advance
..............................
Haresh
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 12
Reputation: senthil_sivanat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
senthil_sivanat senthil_sivanat is offline Offline
Newbie Poster

Re: How to retrive data two times from database in single jsp page.

  #2  
Jul 23rd, 2008
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

<URL SNIPPED>
Last edited by peter_budo : Jul 23rd, 2008 at 3:01 pm. Reason: Keep It Spam-Free - Do not spam, advertise, plug your website, or engage in any other type of self promotion.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JSP Forum

All times are GMT -4. The time now is 1:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC