如果我正确理解了您想要的内容,则代码应如下所示:
int itemsInPage = 100; //Number of item to display in page
int currentPage = 1; //Index of current page, starting from 1
PreparedStatement ps = con.prepareStatement("select title,timestamp,str_to_date(timestamp,'%d/%m/%Y') as date from table_name order by date,title limit " + ((currentPage - 1) * itemsInPage) + ", " + itemsInPage);
ResultSet rs = ps.executeQuery();
String prevTimestamp = null;
while(rs.next()) {
if (prevTimestamp == null || !prevTimestamp.equals(rs.getString(2))) {
System.out.println("*** "+rs.getString(1)+" ***");
}
System.out.println(rs.getString(1));
prevTimestamp = rs.getString(2);
}
如果你在 jsp 中编码,你应该使用
out.print(...);
代替
System.out.println