Paging Records in JSP
| Published on 2/16/2008 by Site Editor More articles 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.*" %>
"); "); // 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 + " "); } 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();
// add your table fields here ....
} |
no comments submitted



