My SQ L 分页主要就是 M yS Q L数据库内置 L I M I T 函数注意添加 my s ql 得 JAR 包 my s q l-c o n nect o r—j av a-5、1、1 3—b in、j a r select * fro m ta b l e LIMIT 5,1 0; // 检索记录行 6—15在中小数据量得情况下,这样得 SQL 足够用了,唯一需要注意得问题就就是确保使用了索引。随着数据量得增加,页数会越来越多,查瞧后几页得 SQL 就可能类似:select * from con t ent o rder by i d d e sc limi t 1000 0, 1 0 一言以蔽之,就就是越往后分页,LIMI T语句得偏移量就会越大,速度也会明显变慢.此时,我们可以通过 2 种方式:一,子查询得分页方式来提高分页效率 s e lect * fr o m 'c o nten t’ w he re id <= (selec t i d fr om ’content' o r der by id desc L I M IT ”、($pag e—1)*$pagesize、", 1) ord er by i d d e sc LIM I T $p a gesize;为什么会这样呢?因为子查询就是在索引上完成得,而普通得查询时在数据文件上完成得,通常来说,索引文件要比数据文件小得多,所以操作起来也会更有效率。 经过飘易得实测,使用子查询得分页方式得效率比纯 LIMI T提高了 14-2 0倍!二,JO I N 分页方式s e lect * from ’content' a s t 1 jo i n (sele c t i d f r om 'c ontent' o rder by id d esc LIMI T "、($p a g e-1)*$p ag esize、”, 1) as t2 where t 1、id 〈= t2、id or d er by t 1、id de sc L IMIT $pages iz e; 经过我得测试,join 分页与子查询分页得效率基本在一个等级上,消耗得时间也基本一致。M ySQL 分页 J a v a实现 〈% p a g e language="jav a" i m p ort=”jav a、ut il、*,ja v a、s q l、*” p ag e Encod ing="gb k"%><!DOCTYP E H T ML PUBL I C ”-//W 3C//DTD HTML 4、01 T ransit iona l//EN”><h t ml> 〈he ad> 〈t i t le>My S QL 分页〈/ti t le〉 </h ead> 〈b ody> 〈ta b l e〉 <t r〉 〈t d>用户名</td> <t d>...