Hi friend,
you do some changes
set per_page variable;
if u want set 20 record per page then
int per_page = 20;
"filename.jsp" change with the name of file u save the code.
<%@ 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 =3;
String name="";
if(offset>1){
ofset = offset*per_page-per_page;
}
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:
mysql://192.168.10.211:3306/";;;
String db = "databasename";
String driver = "com.mysql.jdbc.Driver";
String userName ="";
String password="";
String color = "#F9EBB3";
try {
Class.forName(driver);
conn = DriverManager.getConnection(url+db,userName,password);
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;
}
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="900px" 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>Field 1</b></td>
<td><b>Field 2</b></td>
<td><b>Field 3</b></td>
<td><b>Field 4</b></td>
</tr>