Paging Records in JSP
You can divide database results into pages with this script. This source code is for available to use with MySQL. But you can modify the code to use with PostgreSql and Oracle. You can not use this code with MS-SQL. Becuase MS-SQL does not support using 'LIMIT' in your sql queries. <%@ page import="java.sql.*" %> // add your table fields here .... }
<%
int pages;
Connection ocon = null;
Class.forName("org.gjt.mm.mysql.Driver");
ocon = DriverManager.getConnection("jdbc:mysql:///YOUR_ATABASE", "USERNAME", "PASSWORD");
Statement stmtt = ocon.createStatement();
ResultSet rc = stmtt.executeQuery("Select count(*) from YOUR_TABLE ");
rc.next();
pages = rc.getInt(1);
out.println("Count of Records : " + pages + "<br>");
int cPage;
cPage = (pages / 10) + 1;
if ((cPage * 10) + 1 >= pages)
{
cPage++;
}
out.println("Count of Pages : " + (cPage - 1) + "<br><p><p>");
int p;
for(p = 1; p < cPage ; p++)
{
out.println("<a href=PAGE_NAME.jsp?mv=" + p + ">"+ p +"</a> | ");
}
out.println("<hr>");
// paging
int cpage;
int currentRs;
String pt;
pt = request.getParameter("mv");
if (pt == null)
{
currentRs = 0;
}
else
{
cpage = Integer.parseInt((String)pt);
currentRs = 10 * (cpage - 1);
out.println(cpage + "<br>");
}
Connection con = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///YOUR_ATABASE", "USERNAME", "PASSWORD");
Statement stmt = con.createStatement();
String sql;
sql = "Select * from YOUR_TABLE LIMIT "+ currentRs +",10";
ResultSet rs = stmt.executeQuery(sql);
//rs.absolute(10);
while (rs.next())
{
out.println();
%>
- How to Refresh a web page or redirect to another page
- Custom Paging in ASP Fast And Easy
- Professional Contact Form
- Creating Access Database Connection String
- Using DateDiff function in SQL Statement
- Executing Transact SQL UPDATE statement using SQLCommand
- Custom Paging results in ASPNET using A Better Way
- Sending Emails in JSP
- MySQL AB Offers its Enterprise Database Subscriptions through the New Red Hat Exchange
- Display Top N records from MS Access
- How to display date time in real time
- JSP Hit Counter Free Open Code
- ASP Ikon Ad Manager UPDATED
- Exporting Data From mySQL to Excel
- Generating XML files from SQL Database
- Easy Download Manager Free Version
- ASP Chat Box
- Writing Form Data to Text Files
- Paging Records in JSP
- What is Ecommerce and the Importance of Ecommerce
- Beginning-Ajax-and-ASPNET-35
- How to upload images to mySQL within PHP
- Simple XML RSS Parser
- Counting records in PHP mySQL
- ActiveNews Manager Freeware News Exchange Software
- How to write and use a JavaBean My frst java bean
- Paging Results in PHP
- Free User Registration Form
- A-timesaver-control-GridView
- ASPNET Web Counter Free Open Source Code
- Easy Download Manager Free Version
- ASP Chat Box
- Writing Form Data to Text Files
- Paging Records in JSP
- Beginning-Ajax-and-ASPNET-35
- How to upload images to mySQL within PHP
- Simple XML RSS Parser
- ActiveNews Manager Freeware News Exchange Software
- Counting records in PHP mySQL
- How to write and use a JavaBean My frst java bean
- Paging Results in PHP
- Free User Registration Form
- A-timesaver-control-GridView
- ASPNET Web Counter Free Open Source Code
- Comparing Dates