/**
* 数量统计
* @param sql
* @return
*/
public int getListSize(String sql){
sql = "SELECT COUNT(*) FROM ("+sql+") A";
int count = this.queryForInt(sql);
return count;
}
/**
* oracle 分页
* @param sql
* @param pageNum
* @param pageCount
* @return
* @throws DataAccessException
*/
public List queryForListPage(String sql,int pageNum,int pageCount) throws DataAccessException {
int startNum = (pageNum-1) * pageCount + 1;
int endNum = startNum+pageCount-1;
sql = "SELECT * "+
" FROM (SELECT A.*, ROW_NUMBER() OVER (ORDER BY ID) R FROM (" + sql + ") A " +
" WHERE ROW_NUMBER() OVER (ORDER BY ID) <= "+endNum+") B" +
" WHERE R >= "+startNum;
List list = this.queryForList(sql);
return list;
}
/**
* sql server 分页
* @param sql
* @param pageN
* @param pageC
* @param nameC
* @return
* @throws DataAccessException
*/
public List queryForListPage(String sql, int pageN, int pageC, String nameC) throws DataAccessException {
int sNum = (pageN-1) * pageC + 1;
int eNum = sNum + pageC - 1;
sql = "SELECT A.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY " + nameC + ") AS R, V.* FROM ("
+ sql + ") V) A WHERE A.R BETWEEN " + sNum + " AND " + eNum + " ";
List list = this.queryForList(sql);
return list;
}
/**
* sql server 分页 按时间倒序排序
* @param sql
* @param pageN
* @param pageC
* @param nameC
* @return
* @throws DataAccessException
*/
public List queryForListPageNotice(String sql, int pageN, int pageC, String nameC) throws DataAccessException {
int sNum = (pageN-1) * pageC + 1;
int eNum = sNum + pageC - 1;
sql = "SELECT A.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY " + nameC + ") AS R, V.* FROM ("
+ sql + ") V) A WHERE A.R BETWEEN " + sNum + " AND " + eNum + " ORDER BY CREATE_DATE DESC ";
List list = this.queryForList(sql);
return list;
}
分享到:
相关推荐
标题“Page_SQL(Sqlserver_mysql_oracle_postgre).rar_PAGE_SQL_page”表明这是一个关于如何在不同数据库系统中实现分页查询的资源集合,涉及SQL Server、MySQL、Oracle和PostgreSQL四大主流数据库。 1. **SQL ...
mybatis中,sqlserver分页
本文将深入探讨“Robyn Page SQL Server日期/时间工作台”这一主题,揭示在SQL Server中处理日期/时间操作的实用技巧和策略。 首先,日期/时间数据类型在SQL Server中扮演着至关重要的角色,包括DATE、TIME、...
4. **C#类库设计**:`PageSql.cs`可能包含一个类,该类接收表名、字段名、查询条件和排序条件作为参数,然后内部生成对应的SQL语句。可能还包含了错误处理和SQL注入防护机制。 5. **使用示例**:开发者可以通过实例...
本文详细介绍了如何使用 Oracle SQL Developer 和其他开发工具,包括 Oracle Database Home Page 的使用方法、如何在 Oracle 中使用 SQL*Plus、如何使用 SQL Developer 操作 Oracle 数据库以及如何执行 SQL 语句等...
$pagesql = "select count(*) as ids ".$pagesql; $conn = mysql_query($pagesql) or die(mysql_error()); if($rs = mysql_fetch_array($conn)) $sums = $rs[0]; $pages = ceil(($sums-0.5)/$eachpage)-1; $...
$pagesql = "select count(*) as ids " . $pagesql; $conn = mysql_query($pagesql) or die(mysql_error()); if ($rs = mysql_fetch_array($conn)) $sums = $rs[0]; $pages = ceil(($sums - 0.5) / $eachpage) -...
标题中的"page-by-page.rar_java sql 分页_page_page-by-page_分页 java"指向了一个针对SQL Server数据库的Java分页实现。这个压缩包包含了几个关键文件,如PageDataBaseManager.java、DataBaseManager.java、Pager....
$pagesql = "SELECT COUNT(*) AS ids " . $pagesql; $conn = mysql_query($pagesql) or die(mysql_error()); if ($rs = mysql_fetch_array($conn)) $sums = $rs[0]; $pages = ceil(($sums - 0.5) / $eachpage...
- `public ResultSet querySQL(String countSQL, String pageSQL) throws SQLException`: - 参数说明: - `countSQL`:查询总记录数的SQL语句。 - `pageSQL`:查询当前页数据的SQL语句。 - 功能:执行SQL查询...
$pagesql = "SELECT COUNT(*) AS ids " . substr($pagesql, 4); $conn = mysql_query($pagesql) or die(mysql_error()); if ($rs = mysql_fetch_array($conn)) { $sums = $rs[0]; } $pages = ceil(($sums - ...
$pagesql = "select count(*) as ids " . $pagesql; $conn = mysql_query($pagesql) or die(mysql_error()); if ($rs = mysql_fetch_array($conn)) $sums = $rs[0]; $pages = ceil(($sums - 0.5) / $eachpage) -...
$pagesql = "SELECT COUNT(*) AS ids " . $pagesql; $conn = mysql_query($pagesql) or die(mysql_error()); if ($rs = mysql_fetch_array($conn)) { $sums = $rs[0]; } $pages = ceil(($sums - 0.5) / $...
$pagesql = "select count(*) as ids " . $pagesql; $conn = mysql_query($pagesql) or die(mysql_error()); if ($rs = mysql_fetch_array($conn)) { $sums = $rs[0]; } $pages = ceil(($sums - 0.5) / $each...
$pagesql = "select count(*) as ids " . $pagesql; $conn = mysql_query($pagesql) or die(mysql_error()); if ($rs = mysql_fetch_array($conn)) $sums = $rs[0]; $pages = ceil(($sums - 0.5) / $eachpage) -...
$pagesql = "SELECT COUNT(*) AS ids " . substr($pagesql, strlen("FROM")); $conn = mysql_query($pagesql) or die(mysql_error()); if ($row = mysql_fetch_array($conn)) $sums = $row[0]; $pages = ceil(($...
$pagesql = "SELECT COUNT(*) AS ids " . $pagesql; $conn = mysql_query($pagesql) or die(mysql_error()); if ($rs = mysql_fetch_array($conn)) $sums = $rs[0]; $pages = ceil(($sums - 0.5) / $eachpage) -...
pageSql.sql 是数据库语句 整个执行为:通过传入pageNo(页码),pageSize(每页显示条数)查库,得到一个list数据,并且封装到一个Page对象中,page对象同时还需封装整个所需的所有数据的条数(即数据库中count(*)返回的...