pagination in hibernate with jsp

pagination in hibernate with jsp

Hi, plz give me example on pagination .

View Answers

November 19, 2010 at 11:11 AM

Hi Friend,

We have used MySql database with JSP.

pagination.jsp:

<%@ 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", "root");
ResultSet rs1 = null;
ResultSet rs2 = null;
PreparedStatement ps1=null;
PreparedStatement ps2=null;

int showRows=10;
int totalRecords=10;
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 SQL_CALC_FOUND_ROWS * FROM student limit "+iPageNo+","+showRows+"";
ps1=conn.prepareStatement(query1);
rs1=ps1.executeQuery();
String query2="SELECT FOUND_ROWS() as cnt";
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>
<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><%=rs1.getInt("rollNo")%></td>
<td><%=rs1.getString("name")%></td>
<td><%=rs1.getInt("marks")%></td>
<td><%=rs1.getString("grade")%></td>
</tr>
<%
}
%>

November 19, 2010 at 11:13 AM

continue..

<%
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="pagination.jsp?iPageNo=<%=prePageNo%>&cPageNo=<%=prePageNo%>"> << Previous</a>
<%
}
for(i=((cPage*totalRecords)-(totalRecords-1));i<=(cPage*totalRecords);i++){
if(i==((iPageNo/showRows)+1)){%>
<a href="pagination.jsp?iPageNo=<%=i%>" style="cursor:pointer;color: red"><b><%=i%></b></a>
<%
}
else if(i<=totalPages){
%>
<a href="pagination.jsp?iPageNo=<%=i%>"><%=i%></a>
<%
}
}
if(totalPages>totalRecords && i<totalPages){
%>
<a href="pagination.jsp?iPageNo=<%=i%>&cPageNo=<%=i%>"> >> Next</a>
<%
}
}
%>
<b>Rows <%=startResult%>-<%=endResult%>Total Rows<%=totalRows%> </b>
</div>
</td>
</tr>
</table>
</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();
}
%>

For information on hibernate, visit the following link:

Hibernate Tutorials

Hope that it will be helpful for you. Thanks









Related Tutorials/Questions & Answers:
pagination in hibernate with jsp
pagination in hibernate with jsp  Hi, plz give me example on pagination .   Hi Friend, Visit HereADS_TO_REPLACE_1 Thanks
pagination in hibernate with jsp
pagination in hibernate with jsp  Hi, plz give me example on pagination .   Hi Friend, We have used MySql database with JSP.ADS...;html> <h3>Pagination of JSP page</h3> <body> <form>
Advertisements
Hibernate JSP
In this section, you will learn about Hibernate with JSP using simple pagination example
jsp pagination
jsp pagination  I want to implement pagination on jsp page Each jsp page having some radio buttons, on click of next previous page selected radio buttons are reset. I want to maintain state of selected radio buttons on previous
Pagination in jsp - JSP-Servlet
Pagination in jsp  I need an example of pagination in JSP using display tag
Hibernate Pagination
In this tutorial we will discuss concept of pagination in hibernate
JSP Pagination
I could possibly use??   JSP Pagination pagination.jsp: <%@ page..."); } %> <html><h3>Pagination of JSP page</h3> <body><...JSP Pagination  Hi , I have several JSP's that displays data from
Jsp pagination - JSP-Servlet
tell me the solution  Hi friend, For Jsp pagination application visit to : http://www.roseindia.net/jsp/paging.shtml Thanks...Jsp pagination  Iam doing a online exam application for this i need
pagination - JSP-Servlet
friend, Simple pagination in jsp Simple pagination in JSP... Simple pagination in jsp Displaying Records...pagination  Hi, could u tell me how i will handle pagination
pagination in jsp - JDBC
. Simple pagination in jsp... ------------------   Simple pagination in jsp Simple pagination in JSP Displaying Records
pagination+dynamic pagesize+hibernate - Struts
pagination+dynamic pagesize+hibernate  pagination using hibernate with dynamic page size plzz heilp me
dynamic pagination in jsp - JSP-Servlet
dynamic pagination in jsp  i am unable to display the data in multiple pages. I am gettting data from the database from the javaBeans to jsp by vectors... but i am unable to displaying them in jsp 15 records per page
Pagination - JSP-Servlet
Pagination  I want to display only 10 records but my arraylist contains for example about 100 records... My jsp page should contain 10 records along with the pagination below.... like prev 1 2 3 4 5 next I am using
pagination in JSP - JSP-Interview Questions
pagination in JSP  Hi! Everybody.. I am new to JSP. I am doing project using JSP. Everything is OK. When i am displaying the data from ResultSet... --------------------- Visit for more information. http://www.roseindia.net/jsp/ Thanks
Jsp table Pagination
Jsp table Pagination  I tried the code already.But I dont want it with SQL.I want it for oracle database because I'm using oracle.So please help me with this issue. Thanks
pagination problem - JSP-Servlet
pagination problem   Thanks sir for posting the answer.But i have 2 problems 1.i have created one employee class in that i use getter and setter...(),my problem is that where i have to put & how to do pagination? my code
pagination problem - JSP-Servlet
pagination problem  Thanks sir for posting the answer.But i have 2 problems 1.i have created one employee class in that i use getter and setter...(),my problem is that where i have to put & how to do pagination? my code
Pagination
Pagination  How to implement pagination in struts using hibernate
Pagination
Pagination  How to create pagination in jsp with EJB using MS SQL
Pagination
Pagination  How to apply pagination in JSP. Please help
Hibernate Criteria Pagination
Hibernate Criteria Pagination You can easily make a pagination based application in Hibernate Criteria. You need to do the things that set first result...(end); An example of hibernate criteria pagination is given below
Pagination in jsp using oracle and not sql
Pagination in jsp using oracle and not sql  I need the code for pagination in jsp using oracle. I already tried it with rownum between instead...;Pagination of JSP page</h3> <body> <form> <input type
JSP Hibernate Tutorial
JSP Hibernate Tutorial In this section, you will learn how to use JSP with hibernate. This section contains pagination example using JSP & Hibernate...; encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "
pagination
pagination   Simple way for pagination in jsp using java script to display data without send database
Pagination with condition using servlet or jsp
Pagination with condition using servlet or jsp  Hi, Thanks in advance. I have a requirement like this, In front-end page I have one text...")", Then I want perform the pagination based on the string value(I mean pagination
Pagination
Pagination  I want to know how to use pagination in jsp. I have a list object from that i want to display 3 questions per page can u help me
JSP with hibernate
JSP with hibernate  Hai Friend, As I new To hibernate, I'm facing problem in My project(JSP with hibernate) I need a tutorial who to devllope application with hibernate and jsp ana library jstl only plz can any one help for my
pagination
pagination  How to set pagination using java script to display data
In pagination how to hilight the links - JSP-Servlet
In pagination how to hilight the links  Dear Sir, Thanks for posting the answer,its working fine.Now i want google or others like pagination ,in that if i click on a number only that number color will be changed like
What's wrong with my pagination code in JSP?
What's wrong with my pagination code in JSP?  Dear experts, I've...; print("code sample");   JSP Pagination The given code retrieves...()){ totalRows=rs2.getInt("cnt"); } %> <html><h3>Pagination of JSP
Pagination
Pagination  Is their plug n play approach for creating pagination? 1) Server side as well as client side
Pagination
Pagination  I want to write one where condition in sql query in pagination concept
In pagination how to hilight the links - JSP-Servlet
In pagination how to hilight the links  Dear Sir, In pagination how to highlight the links or how to change the color of that link when i clickon that particular link....Please help me sir.. Some of the code which i
pagination
....   Here is a simple jsp pagination code where we have used mysql database...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP...pagination  I need to give pagination with where condition (query
Pagination
=rs2.getInt("cnt"); } %> Pagination of JSP page Terr_Code Terr_Name
pagination
pagination  I need to give pagination with where condition (query="select * from qtn where qid='"+replyQuesionId+"'limit "+iPageNo+","+showRows+"" ) like this I want, without where condition it is working but with condition
pagination
pagination  how can i start pagination in jsp?   Hi Friend, Try the following code: <%@ page language="java" %> <%@ page import...;Pagination of JSP page</h3> <body> <form> <input type="hidden
Pagination
Pagination  pagination in jsp   Hi Friend, Try the following code: <%@ page language="java" %> <%@ page import="java.sql.*" %>...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP
pagination
;Pagination of JSP page</h3> <body> <form> <input type="hidden... me how to paginate questions without refreshing page   Here is a jsp code of pagination. In the given code,we have taken the database table student
jsp-Hibernate Error - Hibernate
jsp-Hibernate Error  hi, my problem is, I designed an Interface where i am tring to listing the all rows of a table using Iterator and putted a link for deleting each row. I am deleteing row using row id of that record.it delete
pagination
pagination  please let me know how to fetch records from database and display them using paging in jsp and struts
jsp-Hibernate Error - JSP-Servlet
jsp-Hibernate Error  hi, my problem is, I designed an Interface where i am tring to listing the all rows of a table using Iterator and putted a link for deleting each row. I am deleteing row using row id of that record.it delete
Hibernate
Hibernate  how to use pagination concept in Hibernate
upload image using JSP Hibernate
upload image using JSP Hibernate  sir, I want to take image from user and save to database(MYSQL) using Hibernate and JSP Thanks in advance
Login form using Jsp in hibernate - Hibernate
Login form using Jsp in hibernate   Hai Friend, As I new To hibernate, I'm facing problem in My project(JSP with hibernate).. My login form...://www.roseindia.net/struts/hibernate-spring/index.shtml http://www.roseindia.net
pagination in jsf
pagination in jsf  Hi , i am implemeting an online exam system , i have placed my questions as an arraylist in my jsp file within tag , but now i want to paginate these questions based on respective questions by clicking
JSP using java - Hibernate
JSP using java  This is my part of Excal sheet code using jdbc connection. int index=1; while(rs.next()) { HSSFRow row = sheet.createRow((short)index); row.createCell((short)0
Pagination in java
Pagination in java  How to handle pagination when there are records like say in millions in java? Or do we handle this using SQL? I as asked... far good performance then Java pagination. Thanks
jsf pagination
()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP... on please give any solution . Thanks, Bhuban   Here is a jsp code of pagination. In the given code,we have taken the database table student(rollNo,name,marks
Pagination

Ads