欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

jdbc sqlserver 分页

程序员文章站 2024-02-04 09:23:16
...

(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;
}