非常着急,一个实现MySQL分页机制的查询语句~~~~不会写,来帮帮忙!!!!!!!

[复制链接]
查看11 | 回复1 | 2010-6-14 18:46:15 | 显示全部楼层 |阅读模式
我不知道我到底写错了那里大家帮忙看看!!!!
出错显示sql语句错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for .....
int pagesize=3;
int pageCount=0;
int pageNow=1;
int rowCount=0;
try{
String sql;
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tang","root","root");
PreparedStatement pst=(PreparedStatement) conn.prepareStatement("selectcount (*) from stus ");
ResultSet rs = pst.executeQuery();
if(rs.next()){
rowCount = rs.getInt(1);
}
if(rowCount%pagesize==0){
pageCount=rowCount/pagesize;
}else{
pageCount=rowCount/pagesize+1;
}
PreparedStatement psm = (PreparedStatement) conn.prepareStatement("selectpagesize * from stus where stu_id not in(select (pageNow-1)*pagesize stu_id from stus)");
rs=psm.executeQuery();

回复

使用道具 举报

千问 | 2010-6-14 18:46:15 | 显示全部楼层
select * from stus limit (pageNow-1)*pagesize,pagesizeMysql的分页使用Limit limit 参数1,参数2参数1,从第几条开始参数2,返回多少条数据
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行