Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Eswaramoorthy
Code Works
0 Answer(s)      4 years and 4 months ago
Posted in : JSP-Servlet


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();
}
%>





















Advertisement
View Answers

Related Tutorials/Questions & Answers:
Code Works - JSP-Servlet
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 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, TCP/IP is just a protocol that allows different nodes on the network/Internet to share resources and without TRANSMISSION CONTROL PROTOCOL
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
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
Why disable.this works in fireFox but n ot IE
Why 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
How does getcurrentsession() method works in hibernate sessionfactory?
How does getcurrentsession() method works in hibernate sessionfactory?  Hi, Please explain how does getcurrentsession() method works in hibernate sessionfactory? Thanks...   Dear Friend, getCurrentSession() obtains
how to make this java mail works? - Java Beginners
how to make this java mail works?  Dear experts, Recently, I borrowed a book by William Broden and managed to get the source codes from the author himself. The problem is that netbean ide is sending many error message
I invoke the ResultSet methods afterLast and beforeFirst when the method next works.
I invoke the ResultSet methods afterLast and beforeFirst when the method next works.  Why can't I invoke the ResultSet methods afterLast and beforeFirst when the method next works
How Struts 2 Framework works?
How Struts 2 Framework works? This tutorial explains you the working.... In this tutorial you will learn How Struts 2 works with the help of an easy... Struts 2 framework works? Container reads the WEB-INF/web.xml file, which has all
problem on server which works fine on another - Java Server Faces Questions
problem on server which works fine on another  I am having a problem when a tab is clicked, the action listener class is called
How Fleet management System works
If you have a fleet and you are wondering how fleet management system works or how can you can be benefited by managing your fleet, than there is no need to get anxious any more. Fleet management requires some skilled labor, software
code
code  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
code
code  code for android sample program
code
code    how to write this in java
Code
Code  code for connecting c lang to database
How GPS Tracking System Works
Question arise in our mind "How does GPS Tracking system Works"? The Global Positioning system is a navigation system that is used to track objects like vehicles and mobiles. It is based on satellites, maps and computer software. People
code for this is
code for this is  a b c d c b a a b c c b a a b b a a a code
code
code  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
code
code  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
code
code  write a program to encrypt and decrypt the cipher text "adfgvx"   Hi Friend, Try the following code: import java.security.*; import javax.crypto.*; import javax.crypto.spec.*; import java.io.
How Voice over Internet Protocol (VoIP) Works
. It is still a mystery for them the how do voice over IP (VoIP) works. But using VoIP servies is very easy once you know how it works. How VoIP Works? Voice
I can not share my message from the textview on Facebook in Android, but in all other Application works successfully
I can not share my message from the textview on Facebook in Android, but in all other Application works successfully  TextView tv; final String str = getIntent().getExtras().getString("extra"); tv.setText(str); Intent i = new
java code - Java Beginners
java code  Hi !I have already built a program for chatting (with GUI's ),but it works only with single client and single server.Can you please send me a java code for chatting which works with multiple clients an single server
code for program
code for program  hello,I am new to java and need to get the code for a program,i've been trying all sorts of code and nothing works any help would... enclosed in inverted commas thank you. BlockquoteHARDWARE ITEMS CODE
jsp code - JSP-Servlet
jsp code  how to count no of clicks made on a link and save it on database( using jsp)  Hi Friend, Try the following code: 1... it works
How Ajax Works
How Ajax Works         How Ajax Works Ajax adds an extra layer of functionality in the communication model. Ajax engine acts
How jQuery works?
How jQuery Works?      This section we will see how jQuery works with the help of simple program... from the server. So, jQuey is very useful tool. Let's see how it works
JAVA code For
JAVA code For   JAVA code For "Traffic signals Identification for vehicles
c code
c code  c code for this formula x=(y-0.22z-072)4; where y=7.32 x=3.1 then ans x=23.9 end code for this   c code for this formula x=(y-0.22z-072)4; where y=7.32 x=3.1 then ans x=23.9 can any one end code
jsp code
jsp code  what are the jsp code for view page in online journal
stegnography code
stegnography code  code for the digital stegnographic technique for the encryption and decryption of image
example code
example code  code for displaying a list from another class on a midlet
Code for a triangle.....
Code for a triangle.....   1 1 5 1 1 5 25 5 1 What is the source Code for above output
c code
c code  c code for this formula x=(y-0.22z-072)4; where y=7.32 x=3.1 then ans x=23.9 end code
JSF code
need jsf code that will populate combo box values from the database  Hi, i'm new on JSf,I need jsf code that will populate combo box values from the database when the form runs
Code for Pattern
Code for Pattern   * * * * * * * * Please write the code of above program and please do not use in this string tokennizer, string buffer etc i mean to say that please use very simple method
Code for Pattern
Code for Pattern   * * * * * * * * * * * Please write the code of above program and please do not use in this string tokennizer, string buffer etc i mean to say that please use very simple method
Code for Pattern
Code for Pattern   * *** * * Please write the code of above program and please do not use in this string tokennizer, string buffer etc i mean to say that please use very simple method
java code
java code  write a java code to convert hindi to english using arrays
JAVA CODE
JAVA CODE  JAVA SOURCE CODE TO BLOCK A PARTICULAR WEB SITES(SOCIAL WEB SITE
Advertisements
 

 

 

DMCA.com