首页 > 数据库技术 > 详细

sql 分页查询

时间:2019-12-24 12:46:20      阅读:87      评论:0      收藏:0      [点我收藏+]
public List<Student>list = new ArrayList<>(int page) {
	
	try {
		Class.forName("com.mysql.jdbc.Driver");
	} catch (ClassNotFoundException e1) {
		e1.printStackTrace();
	}
	
	try (Connection connection = DriverManager.getConnection(url, user, pass)) {
		int size =2;
		
		String sql = "SELECT * FROM student order by asc limit ?,?";
		java.sql.PreparedStatement statement = connection.prepareStatement(sql);

		int p = (page-1)*size;//分页id算法,用于计算开始id
		
		statement.setInt(1, p);
		statement.setInt(2,size);

	} catch (SQLException e) {
		e.printStackTrace();
	}
}

  

sql 分页查询

原文:https://www.cnblogs.com/max-hou/p/12090741.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!