Code Works
Hi
The code provided is working fine along with the pagination . i edited the queries and that makes difference..
here is the code.
Thank you
Regards
Eswaramoorthy
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%!
public int nullIntconvert(String str){
int num=0;
if(str==null) {
str="0";
}
else if((str.trim()).equals("null")) {
str="0";
}
else if(str.equals("")) {
str="0";
}
try{
num=Integer.parseInt(str);
}
catch(Exception e) { }
return num;
}
%>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "eswar");
ResultSet rs1 = null;
ResultSet rs2 = null;
PreparedStatement ps1=null;
PreparedStatement ps2=null;
int showRows=5;
int totalRecords=20;
int totalRows=nullIntconvert(request.getParameter("totalRows"));
int totalPages=nullIntconvert(request.getParameter("totalPages"));
int iPageNo=nullIntconvert(request.getParameter("iPageNo"));
int cPageNo=nullIntconvert(request.getParameter("cPageNo"));
int startResult=0;
int endResult=0;
if(iPageNo==0){
iPageNo=0;
}
else{
iPageNo=Math.abs((iPageNo-1)*showRows);
}
String query1="SELECT * FROM student limit "+iPageNo+","+showRows+"";
//String query1="SELECT SQL_CALC_FOUND_ROWS * FROM student limit ";
ps1=conn.prepareStatement(query1);
rs1=ps1.executeQuery();
String query2="SELECT count(*) as cnt from student";
ps2=conn.prepareStatement(query2);
rs2=ps2.executeQuery();
if(rs2.next()) {
totalRows=rs2.getInt("cnt");
System.out.println(totalRows);
}
%>
<html>
<h3>Pagination of JSP page</h3>
<body>
<form method="post" action="upgrid.jsp">
<input type="hidden" name="iPageNo" value="<%=iPageNo%>">
<input type="hidden" name="cPageNo" value="<%=cPageNo%>">
<input type="hidden" name="showRows" value="<%=showRows%>">
<table width="100%" cellpadding="0" cellspacing="0" border="1" >
<tr>
<td>Roll No</td>
<td>Name</td>
<td>Marks</td>
<td>Grade</td>
</tr>
<%
while(rs1.next()){
%>
<tr>
<td><input type="text" name="no" size="38" value="<%=rs1.getInt("rollNo")%>"></td>
<td><input type="text" name="name" size="38" value="<%=rs1.getString("name")%>"></td>
<td><input type="text" name="marks" size="38" value="<%=rs1.getInt("marks")%>"></td>
<td><input type="text" name="grade" size="38" value="<%=rs1.getString("grade")%>"></td>
</tr>
<%
}
%>
<%
try{
if(totalRows<(iPageNo+showRows)) {
endResult=totalRows;
}
else{
endResult=(iPageNo+showRows);
}
startResult=(iPageNo+1);
totalPages=((int)(Math.ceil((double)totalRows/showRows)));
}
catch(Exception e){
e.printStackTrace();
}
%>
<tr>
<td colspan="3">
<div>
<%
int i=0;
int cPage=0;
if(totalRows!=0) {
cPage=((int)(Math.ceil((double)endResult/(totalRecords*showRows))));
int prePageNo=(cPage*totalRecords)-((totalRecords-1)+totalRecords);
if((cPage*totalRecords)-(totalRecords)>0){
%>
<a href="newjsp.jsp?iPageNo=<%=prePageNo%>&cPageNo=<%=prePageNo%>"> << Previous</a>
<%
}
for(i=((cPage*totalRecords)-(totalRecords-1));i<=(cPage*totalRecords);i++){
if(i==((iPageNo/showRows)+1)){%>
<a href="newjsp.jsp?iPageNo=<%=i%>" style="cursor:pointer;color: red"><b><%=i%></b></a>
<%
}
else if(i<=totalPages){
%>
<a href="newjsp.jsp?iPageNo=<%=i%>"><%=i%></a>
<%
}
}
if(totalPages>totalRecords && i<totalPages){
%>
<a href="newjsp.jsp?iPageNo=<%=i%>&cPageNo=<%=i%>"> >> Next</a>
<%
}
}
%>
<b>Rows <%=startResult%>-<%=endResult%>Total Rows<%=totalRows%> </b>
</div>
</td>
</tr>
</table>
<input type="submit" value="Update">
</form>
</body>
</html>
<%
try{
if(ps1!=null){
ps1.close();
}
if(rs1!=null){
rs1.close();
}
if(ps2!=null){
ps2.close();
}
if(rs2!=null){
rs2.close();
}
if(conn!=null){
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
View Answers
Related Tutorials/Questions & Answers:
Code Works - JSP-ServletCode Works Hi
The
code provided is working fine along with the pagination . i edited the queries and that makes difference..
here is the
code.
Thank you
Regards
Eswaramoorthy
Pagination of JSP page
VoIP Works
VoIP
Works
How VoIP
Works
If you've never heard of VoIP...;
How VoIP
Works-Busting Out of Long Distance Rates... over Internet Protocol, and how VoIP
works is actually quite revolutionary because
Advertisements
How TCP/IP works ?How TCP/IP
works ? hello,,
Can some body tell me how TCP/IP
works?
hii,ADS_TO_REPLACE_1
TCP/IP is just a protocol that allows different nodes on the network/Internet to share resources and without TRANSMISSION
Works only for one row Works only for one row Hi,
My below
code is working only if there is a single row. could you please help me in doing it for all the rows retrieved from the database.
<%@page import="java.util.concurrent.CountDownLatch
Maven Dependency works-bolts >> 1.0.0You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-bolts version1.0.0 in your project
Maven Dependency works-bolts >> 1.0.4You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-bolts version1.0.4 in your project
Maven Dependency works-http >> 1.0.0You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-http version1.0.0 in your project
Maven Dependency works-http >> 1.0.1You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-http version1.0.1 in your project
Maven Dependency works-http >> 1.0.3You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-http version1.0.3 in your project
Maven Dependency works-http >> 1.0.4You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-http version1.0.4 in your project
Maven Dependency works-util >> 1.0.1You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-util version1.0.1 in your project
Maven Dependency works-util >> 1.0.2You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-util version1.0.2 in your project
Maven Dependency works-util >> 1.0.4You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-util version1.0.4 in your project
Maven Dependency works-widget >> 1.0.1You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-widget version1.0.1 in your project
Maven Dependency works-widget >> 1.0.2You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-widget version1.0.2 in your project
Maven Dependency works-widget >> 1.0.4You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-widget version1.0.4 in your project
Maven Dependency works-http >> 1.0You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-http version1.0 in your project
Maven Dependency works-http >> 1.0.2You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-http version1.0.2 in your project
Maven Dependency works-http >> 1.0.5You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-http version1.0.5 in your project
Maven Dependency works-util >> 1.0You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-util version1.0 in your project
Maven Dependency works-util >> 1.0.3You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-util version1.0.3 in your project
Maven Dependency works-widget >> 1.0You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-widget version1.0 in your project
Maven Dependency works-widget >> 1.0.3You should include the dependency
code given in this page to add Maven Dependency of com.mobilesolutionworks >>
works-widget version1.0.3 in your project
codecode Heris the javascript code.It
works ffine but i would like to know what is the meaning of line this.SetData=SetData and next three lines after this(in bold) because when i remove them and try calling the functions via object
ModuleNotFoundError: No module named 'aws-works'ModuleNotFoundError: No module named 'aws-
works' Hi,
My Python... 'aws-
works'
How to remove the ModuleNotFoundError: No module named 'aws-
works' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'aws-works'ModuleNotFoundError: No module named 'aws-
works' Hi,
My Python... 'aws-
works'
How to remove the ModuleNotFoundError: No module named 'aws-
works' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'aws-works'ModuleNotFoundError: No module named 'aws-
works' Hi,
My Python... 'aws-
works'
How to remove the ModuleNotFoundError: No module named 'aws-
works' error?
Thanks
Hi,
In your python environment you
Works when run from desktop but....Works when run from desktop but.... I used the
code provided here for a pie chart using swing in Java, and when I saved it to my desktop, it ran fine, and worked as explained, but then I tried to add the same
code to NetBeans
CodeCode
code for connecting c lang to database
code code
how to write this in java
codecode
code for android sample program
codecode please provide
code for custom tags.by using currdate tag we need to get current date?please give me
code code code hi
I need help in creating a java
code that reminds user on a particular date about their festival.
i have no clue of how to do it..
am looking forward to seek help from you
code the correct
code for a program.The output of the program is listed below...: {Block 5}
ADDRESS-3: {San Juan}
POST
CODE:{6745}
ENTER
CODE (XX TO stop)
CODE:{FF1}
QUANTITY:{2}
CODE:{TR4}
QUANTITY:{1}
CODE:XX
INVOICE FOR YOUR ORDER
Harry
code code to create the RMI
client on the local machine:
import java.rmi.*;
public... : "+e);
}
}
}
However, when the preceding
code is executed it results... the correct
code codecode i have four textboxes.whenever i click on up,down,left or down arrows then the cursor move to another textbox based on the key pressed.i want
code for this in javascript
code line of
code to print the amount he should be paid as allowance
codecode write a program to encrypt and decrypt the cipher text "adfgvx"
Hi Friend,
Try the following
code:ADS_TO_REPLACE_1
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import
Why disable.this works in fireFox but n ot IEWhy disable.this
works in fireFox but n ot IE When I put this line of
code in my program, it
works beautifully in firefox, but does not submit when using IE
<input type="submit" id="9" value="Generate Report" onclick