•
•
•
•
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
![]() |
•
•
Join Date: Jun 2008
Posts: 37
Reputation:
Rep Power: 0
Solved Threads: 0
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:
Thanks in advance
..............................
Haresh
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")%>: <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> <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
•
•
Join Date: Jan 2008
Posts: 12
Reputation:
Rep Power: 0
Solved Threads: 0
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>
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access advice age amd avatar backup blue gene combo daniweb data data protection database dos dropdownlist economy encryption energy europe forensic forensics hardware help ibm ibm. news intel ibm it linux medicine memory microsoft module news open source openoffice pc privacy ps3 recession red hat russia security server storage sun supercomputer supercomputing technology trends web working
- Previous Thread: resultset within the resultset
- Next Thread: cheap jsp webhosting


Linear Mode