Home Answers Viewqa Hibernate pagination in hibernate with jsp

 
 


kirankumar.g
pagination in hibernate with jsp
2 Answer(s)      2 years and 6 months ago
Posted in : Hibernate

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 Pages:
pagination in hibernate with jsp
pagination in hibernate with jsp  Hi, plz give me example on pagination .   Hi Friend, Visit Here 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...>Pagination of JSP page</h3> <body> <form> <input type
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
pagination
pagination   Simple way for pagination in jsp using java script to display data without send database
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
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  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
pagination
pagination  please let me know how to fetch records from database and display them using paging in jsp and struts
Hibernate JSP
In this section, you will learn about Hibernate with JSP using simple pagination example
Hibernate Pagination
In this tutorial we will discuss concept of pagination in hibernate
Pagination in jsp - JSP-Servlet
Pagination in jsp  I need an example of pagination in JSP using display tag
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
pagination+dynamic pagesize+hibernate - Struts
pagination+dynamic pagesize+hibernate  pagination using hibernate with dynamic page size plzz heilp me
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
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 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
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
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
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
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 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
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
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...'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate
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
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
Hibernate
Hibernate  how to use pagination concept in Hibernate
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
pagination
pagination  How to set pagination using java script to display data
Pagination Using Displaytag Lib
Pagination Using Displaytag Lib  I am using Struts 1.2 for my web based project. While using display tag lib in jsp for pagination, is there any substitute of using As I dont want to be dependent on any site(s). Please
Pagination Example
a JSP page that contains pagination code: Here is the code to be added...; In this section, you will learn how to create pagination in struts 2. For creating pagination in your application follows the certain steps: Download
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
Paging or pagination - Development process
Paging or pagination  1.how to do paging or pagination in jsp using... to get a correct values... I m sending my jsp code also please help me sir...("Starting index is "+startIndex); %> Pagination The Following
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
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
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
store pagination form fields - Struts
store pagination form fields   hi,iam working online exams project... table. here iam using pagination for questions to be displayed to client... approach this task. iam using jstl in jsp to iterate the list object of different
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
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
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
datagrid search - Hibernate
datagrid search  Hi friend, i have displayed a datagrid using jsp but i need a search option in that which is used to display and sort... with pagination? Please clarify. Thanks
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.