Home  >  Article  >  Database  >  jdbc sqlserver 分页

jdbc sqlserver 分页

WBOY
WBOYOriginal
2016-06-07 15:39:411269browse

(1). top ... not in , (2). top .... id( max ),(3).游标 这种方法感觉比上面三种要快 ,分享一下跟好的意见 使用的是org.springframework.jdbc.core. JdbcTemplate limit = 25; public ListMapString, Object findAll(String type, final int start, f

(1). top  ... not in  , (2). top .... id>(max),(3).游标 

这种方法感觉比上面三种要快 ,分享一下跟好的意见

使用的是 org.springframework.jdbc.core.JdbcTemplate


limit = 25;
public List> findAll(String type, final int start, final int limit) {
StringBuilder builder = new StringBuilder();
List params = new ArrayList();//给占位符赋值
builder.append("select top " + (start + limit)//第一页,start=0 ()select top 25 * ,第二页 start=25 (select top 50 *)
+ " * from v_fulldata a where 1=1");
if (type != null && type != " ") {
builder.append(" and a.atype = ? ");
params.add(type);
}
builder.append(" order by wg13 desc;");

String sql = builder.toString();
List> list = (List>) getJdbc()
.query(sql, params.toArray(), new ResultSetExtractor() {
@Override
public Object extractData(ResultSet rs)
throws SQLException, DataAccessException {
List> list = new ArrayList>();
while (rs.next()) {  //将查询结果循环
if (rs.getRow() continue;
}
Map row = new HashMap();
ResultSetMetaData rsmd = rs.getMetaData();
for (int i = 1; i row.put(rsmd.getColumnName(i), rs.getString(i));
}
list.add(row);
}
return list;
}
});
return list;
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn