August 29, 2008 at 12:48 PM
Hi friend,
<%@ page language="java" import="java.sql.*;"%>
<html>
<head>
<title>pagination using jsp with database</title>
</head>
<body>
<br><br><br>
<%
int offset=0;
int ofset = 0;
if(request.getParameter("offset")!=null) {
offset= Integer.parseInt(request.getParameter("offset").toString());
}
int total_count = 0;
int total_page = 0;
int per_page =1;
String name="";
if(offset>1){
ofset = offset*per_page-per_page;
}
if((request.getParameter("userid")!=null) && request.getParameter("userid")!="")
{
String user = session.getAttribute("userid").toString();
String userid = request.getParameter("userid");
String sd[] = request.getParameter("sdate").toString().split("-");
String ed[] = request.getParameter("edate").toString().split("-");
String sdate = sd[2]+"-"+sd[0]+"-"+sd[1] ;
String edate = ed[2]+"-"+ed[0]+"-"+ed[1];
System.out.println("MySQL Connect Example.");
Connection con = null;
String url = "jdbc:
mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String password="amar123";
String color = "#F9EBB3";
try {
Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,password);
Statement stcount = con.createStatement();
String strQuerycount = "select count(*) from Userdetail";
ResultSet rscount = stcount.executeQuery(strQuerycount);
if(rscount.next()){
total_count=rscount.getInt(1);
}
if(total_count%per_page==0){
total_page = total_count/per_page;
}
else{
total_page = total_count/per_page+1;
}
out.println(total_count);
out.println(total_page);
out.println(ofset);
if(offset>1)
{
int previous = offset-1;
%>
<td>
</td>
<%
}
if(total_page>0)
{
for(int i=1;i<=total_page;i++)
{
if(i==offset)
{
%>
<td>
<%=i%></td>
<%
}
else{
%>
<td>
</td>
<%
}
}
}
if(offset<total_page)
{
int next = offset+1;
%>
<td>
<a href="viewTransaction.jsp?userid=<%=userid%>&username=<%=request.getParameter("username")%>&lastname=<%=request.getParameter("lastname")%>&offset=<%=next%>">Next</a></td>
<%
}
Statement st1 = con.createStatement();
String strQuery1 = "select * from Userdetail";
ResultSet rs1 = st1.executeQuery(strQuery1);
if(rs1.next()) {
name =rs1.getString(1);
}
Statement st = con.createStatement();
String strQuery = "select * from Userdetail";
// out.println(strQuery);
ResultSet rs = st.executeQuery(strQuery);
int count=offset-1;
%>
August 29, 2008 at 12:50 PM
<table style="padding-left:150px;">
</table>
<br><br><br>
<table width="700px" align="center" style="border:1px solid #000000;">
<tr>
<td colspan=8 align="center" style="background-color:ffeeff"><b>Transaction</b></td>
</tr>
<tr style="background-color:efefef;">
<td><b>SNo</b></td>
<td><b>UserName</b></td>
<td><b>LastName</b></td>
<td><b>E-mail</b></td>
<td><b>Date Of Birth</b></td>
<td><b>Country</b></td>
<td><b>State</b></td>
</tr>
<%
while(rs.next())
{
if((count%2)==0){
color = "#eeffee";
}
else
{
color = "#F9EBB3";
}
count++;
%>
<tr style="background-color:<%=color%>;">
<td><%=count%></td>
<td><%=rs.getInt(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><%=rs.getString(6)%></td>
<td><%=rs.getString(7)%></td>
</tr>
<%
}
if(count==0)
{
%>
<tr style="background-color:<%=color%>;">
<td colspan=8 align="center">No Record</td>
</tr>
<%
}
System.out.println("Connected to the database");
con.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
%>
</table>
<br>
<table width="800px">
<tr><td width="100%" align="right">Go Back</a></td></tr>
</table>
</body>
</html>
-----------------------------
Read for more information.
http://www.roseindia.net/jsp/Thanks.
amardeep
August 29, 2008 at 12:51 PM
Hi friend,
Complete code for paging
Do some changes
1.tablename,filename,databasename,
per_page : no of records to show per page:
<%@ page language="java" import="java.sql.*;"%>
<html>
<head>
<style>
A:hover {
text-decoration: none;
font-family:arial;
font-size:12px;
color: #000000;
BORDER: none;
}
A {
text-decoration: underline;
font-family:arial;
font-size:12px;
color: #000000;
BORDER: none;
}
</style>
</head>
<body>
<br><br><br>
<%
int offset=0;
int ofset = 0;
if(request.getParameter("offset")!=null) {
offset= Integer.parseInt(request.getParameter("offset").toString());
}
int total_count = 0;
int total_page = 0;
int per_page =10;
String name="";
if(offset>1){
ofset = offset*per_page-per_page;
}
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:
mysql://localhost:3306/";;
String dbName = "databasename";
String driver = "com.mysql.jdbc.Driver";
String username = "root";
String userPassword = "root";
String color = "#F9EBB3";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,username,userPassword);
Statement stcount = conn.createStatement();
String strQuerycount = "select count(*) from tablename ";
ResultSet rscount = stcount.executeQuery(strQuerycount);
if(rscount.next())
{
total_count=rscount.getInt(1);
}
if(total_count%per_page==0)
{
total_page = total_count/per_page;
}
else
{
total_page = total_count/per_page+1;
}
//out.println(total_count);
//out.println(total_page);
//out.println(ofset);
Statement st = conn.createStatement();
String strQuery = "select * from tablename limit "+ofset+","+per_page;
// out.println(strQuery);
ResultSet rs = st.executeQuery(strQuery);
// out.println("offset " + offset);
int count=0;
if(offset>1)
count=offset*per_page-per_page;
%>
<br><br><br>
<table width="700px" align="center" style="border:1px solid #000000;" >
<tr>
<td colspan=8 align="center" style="background-color:ffeeff"><b>Transaction Report</b></td>
</tr>
<tr style="background-color:efefef;">
<td><b>SNo</b></td>
<td><b>Fieldname</b></td>
</tr>
<%
while(rs.next()){
if((count%2)==0){
color = "#eeffee";
}
else{
color = "#F9EBB3";
}
count++;
%>
<tr style="background-color:<%=color%>;">
<td><%=count%></td>
<td>fieldvalue</td>
</tr>
Related Tutorials/Questions & Answers:
PagingPaging How does
paging in struts by use oracle database?
Thanks in advance
paging in Jsp: jsp code - JSP-Servletpaging in
Jsp:
jsp code Sir/Madam-
i m working on
jsp . i want to perform
paging in
jsp file so that we don't need to scroll page...;Hi friend,
Complete
code for
paging
Do some changes
1.tablename
Advertisements
paging - Ajaxpaging i want sample
code for
paging using pager taglibs
JSP Paging issueJSP Paging issue Hi;
How to display large number of users- account profile with photo can be placed in continuous pages using
JSP code . If any one have solution please help me .
Amrit;
Visit Here
Paging in jsp - Java BeginnersPaging in jsp Hi all,
I want to make
paging in
jsp please send the
code and process also.
Like 1,2,3,4. its urgent...please send Hi Friend,
Try the following
code:
pagination.jsp
Paging in JSP - JSP-ServletPaging in JSP Sir,
The error shows in SELECT Query while executing the following query in
Paging
"SELECT * FROM tablename LIMIT 0,10"
What is the exact query in MsAccess for Using Limit.Thsmk you
for ur replies
JSP Paging issueJSP Paging issue Hi;
what should I have to write insted of "SQLCALCFOUND_ROWS" for MS-SQL database
Amrit
Server side Paging in jsp ?Server side
Paging in
jsp ? Hi
i am student of It .
i am learning
jsp-servlet and i am trying to do
paging in my report generation but i want to do server side
paging and i am using oracle 10g in back end .
it will be very
Paging or pagination - Development processPaging or pagination 1.how to do
paging or pagination in
jsp using servlets?
I have a 20 records ,i have to show them in 2 pages like pages 1 2... to get a correct values...
I m sending my
jsp code also please help me sir
datagid with paging using jsp - Ajaxdatagid with
paging using jsp datagrid with
paging using ajax and jsp Hi friend,
For read more information :
http://www.roseindia.net/
jsp/data-grid.shtml
Thanks
how to make paging with function ?how to make
paging with function ? how to make
paging with function... ");
//this page in only function call and next page in function body
paging($offset... Document
<?php</p>
function
paging($offset,$rowsPerPage,$query
how to make paging with class and ajaxhow to make
paging with class and ajax
paging with class and ajax...;
paging with class and ajax
function showUser(str)
{
if (window.XMLHttpRequest)
{//
code JSP Paging Example in Datagrid - JSP-ServletJSP Paging Example in Datagrid Hi,
I have tested
JSP Paging Example... it successfully.
http://www.roseindia.net/
jsp/paging.shtml
When i try... on the url
http://www.roseindia.net/
jsp/paging.shtml
is customizable or not if yes
jsp paging - JSP-Interview Questionsjsp paging I am working in
JSP paging with ms-access but i have..." is created Correct or not.
For more on
Paging in
JSP visit to :
http... or not.
For more on
Paging in
JSP visit to :
http://www.roseindia.net/
jsp JSP Paging Example in Datagrid JSP Paging Example in Datagrid
... to create
paging in
JSP. Two files are used "paging.jsp" and "Employee.java" in
the
code given below.
Brief description of the flow
JSP Paging Example in Datagrid - JSP-ServletJSP Paging Example in Datagrid Hello,
This is with refernece to the
paging smaple provided on the URL
http://www.roseindia.net/
jsp/paging.shtml... Folder Name is datagridsample that has a
jsp page named search.jsp
WEBINF\lib
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
Pagination in PHP code - PHPPagination in PHP code 3.Pagination in PHP codeIs it possible to get the
paging in PHP without database call? How will I show the image instead of numbering? any
code that can help
CodeCode how to print this??
with the use of only
JSP.......
1
23
456
78910
Here is the
jsp number pattern example:
1
2 3
4 5 6
7 8 9 10
<%@page language="java"%>
<%
int k = 1;
for(int i=1; i<= 4 ;i
JAVA code For JAVA
code For JAVA
code For "Traffic signals Identification for vehicles
example codeexample code
code for displaying a list from another class on a midlet
stegnography codestegnography code
code for the digital stegnographic technique for the encryption and decryption of image
jsp codejsp code what are the
jsp code for view page in online journal
c codec 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 Source codeSource code source
code of html to create a user login page
c codec 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 Code for PatternCode 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 PatternCode 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