jsp分页中SQL语句传参数的写法
小弟在写一个JSP调用低层方法的分页。
在SQL语句部分是这样的:
sql = "select * FROM ( SELECT A.*, ROWNUM RN FROM (select * from All_UsageReport_THISMONTH) A WHERE ROWNUM <= "+ currentPage* pageSize+ ") WHERE RN > = " + i;
以下是JSP代码:
<%@ page contentType= "text/html; charset=UTF-8 "%>
<%@ page import= "java.sql.Connection "%>
<%@ page import= "java.sql.PreparedStatement "%>
<%@ page import= "java.sql.ResultSet "%>
<%@ page import= "com.trs.yellow.db.DBAccess "%>
<%@ page import= "com.trs.yellow.dao.QueryLog "%>
<%@ page import= "com.trs.yellow.dao.PageBean "%>
<%@ page import= "java.lang.String "%>
<%@ page import= "java.sql.CallableStatement "%>
<%@ page import= "java.sql.DriverManager "%>
<%@ page import= "com.trs.hxt.wcmsz.SplitString "%>
<%@ page import= "com.trs.cdsx.common.*,com.trs.cdsx.toll.* "%>
<%@ page import= "java.lang.String "%>
<script src= "admin/toll/include/objs_related.js "> </script>
<script LANGUAGE= "javascript ">
function submit10()
{
self.location.replace( "fenye1.jsp ")
}
</script>
<%
//String tablename = request.getParameter( "tablename ");
Connection conn; //数据库连接对象
PreparedStatement pstmt; //SQL语句对象
ResultSet rs; //结果集对象
String url2; //数据库连接字符串
String sql;
int totalRecords = QueryLog.getInstance().size( "All_UsageReport_THISMONTH ");
// 每页显示记录数量
int pageSize = 20;
// 当前页数
int currentPage = 0;
if (request.getParameter( "page ") == null) {
currentPage = 1;
} else {
currentPage = Integer.parseInt(request.getParameter( "page "));
}
// 初始化PageBean对象
PageBean pageBean = new PageBean(totalRecords, pageSize, currentPage);
// 计算当前显示页面的第一条起始记录数
int start = pageBean.getStart();
//装载JDBC驱动程序
Class.forName( "oracle.jdbc.driver.OracleDriver ");
//设置数据库连接字符串
url2 = "jdbc:oracle:thin:@203.194.142.214:1521:isinodb ";
//连接数据库
conn = DriverManager.getConnection(url2, "isinolog_viewer ", "isino ");
int i = (currentPage -1) * pageSize+1;
//sql = "select * from All_UsageReport_THISMONTH ";
sql = "select * FROM ( SELECT A.*, ROWNUM RN FROM (select * from All_UsageReport_THISMONTH) A WHERE ROWNUM <= "+ currentPage* pageSize+ ") WHERE &nb