java分段读取数据问题 不同数据库有不同的写法 这个好像更应该是sql怎么写 而不是java怎么写啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用的mysql 我是想用JAVA 代码 循环控制分页 sql的分页的问题吧,每个数据库都不一样的! mysql记得好像是limit n,m来控制的 对于mysqlLIMIT子句可以用来限制由SELECT语句返回过来的数据数量,它有一个或两个参数,如果给出两个参数, 第一个参数指定返回的第一行在所有数据中的位置,从0开始(注意不是1),第二个参数指定最多返回行 数。例如: select * from table LIMIT 5,10; #返回第6-15行数据 select * from table LIMIT 5; #返回前5行 select * from table LIMIT 0,5; #返回前5行 其实最好sql分页java的话速度会慢的如果java分页要个算法了。比如if(pageNum < pageSum-1){ for (int i = startNum; i < startNum + rowNum; i++) { pageList.add(list.get(i)); } }else{ if(list.size()==rowNum||rowNum==1 || list.size()%rowNum==0){ for (int i = startNum; i < startNum + rowNum; i++) { pageList.add(list.get(i)); } }else{ for (int i = startNum; i < startNum + list.size()%rowNum; i++) { pageList.add(list.get(i)); } } } 我知道mysql 是 limit 分页! 我现在的问题是要limit 后面的字符串要循环变动如 100条我每次去30跳的话limit 后面的数据变成 limit 0,30 limit 30,60 limit 60,90 limit 90,100 int count//次数//传进来countif(count==4)sql="select * from table LIMIT 90,100";else{sql="select * from table LIMIT "+(30*(count-1))+","+(30*count);} currentPage //当前页rowsPerPage //每页显示的记录的条数select * from table limit (currentPage-1)*rowsPerPage,rowsPerPage; final int offset = 30;int startIndex = 0;int length = 100;//select count(*) from table的结果值。while(startIndex+offset<length){ executeSQL(startIndex,offset); startIndex+=offset;}executeSQL(startIndex,length-startIndex);public void executeSQL(int startIndex,int offset){ String sql = "select * from table limit "+startIndex+", "+offset; //...} 读到一篇很困惑的线程安全的文章 split多个# 好的问题 异常抓取问题! 在做插件开发,请教一个基本问题 一个简单的画图问题~白送分了~ 执行ResultSet.next()方法时,为什么还不断访问数据库啊。急!!! 关于JButton的Icon,以及java编译的两个小问题 如何使用 GridBagConstraints 的几个格子来显示一个控件 Vector 和 ArrayList到底有什么区别? 高手都上班了么?这么简单的问题怎么没人答 坦克大战 为什么在传送数据的时候出现错误
我是想用JAVA 代码 循环控制分页
LIMIT子句可以用来限制由SELECT语句返回过来的数据数量,它有一个或两个参数,如果给出两个参数,
第一个参数指定返回的第一行在所有数据中的位置,从0开始(注意不是1),第二个参数指定最多返回行
数。例如:
select * from table LIMIT 5,10; #返回第6-15行数据
select * from table LIMIT 5; #返回前5行
select * from table LIMIT 0,5; #返回前5行
比如
if(pageNum < pageSum-1){
for (int i = startNum; i < startNum + rowNum; i++) {
pageList.add(list.get(i));
}
}else{
if(list.size()==rowNum||rowNum==1 || list.size()%rowNum==0){
for (int i = startNum; i < startNum + rowNum; i++) {
pageList.add(list.get(i));
}
}else{
for (int i = startNum; i < startNum + list.size()%rowNum; i++) {
pageList.add(list.get(i));
}
}
}
我知道mysql 是 limit 分页! 我现在的问题是要limit 后面的字符串要循环变动
如 100条我每次去30跳的话limit 后面的数据变成
limit 0,30
limit 30,60
limit 60,90
limit 90,100
//传进来count
if(count==4)
sql="select * from table LIMIT 90,100";
else{
sql="select * from table LIMIT "+(30*(count-1))+","+(30*count);
}
rowsPerPage //每页显示的记录的条数
select * from table limit (currentPage-1)*rowsPerPage,rowsPerPage;
int startIndex = 0;
int length = 100;//select count(*) from table的结果值。
while(startIndex+offset<length){
executeSQL(startIndex,offset);
startIndex+=offset;
}
executeSQL(startIndex,length-startIndex);
public void executeSQL(int startIndex,int offset){
String sql = "select * from table limit "+startIndex+", "+offset;
//...
}