Java MYSQL paging, javamysql Paging
Query statements in MySql implement Paging
Statement:
Select * from table name where condition limit: the page number and the number of rows on each page;
Import java. util. *; import java. SQL. *; public class FruitDao {private Connection conn; private PreparedStatement pre; private ResultSet rs; public FruitDao () throws Exception {conn = DBConnection. aa ();} // total number of returned pages public int yeshu (int meiyegeshu) throws SQLException {// number of rows int yeshu = 0; String SQL = "select count (*) from fruit "; pre = conn. prepareStatement (SQL); rs = pre.exe cuteQuery (); rs. next (); Int hangshu = rs. getInt (1); // calculate the number of pages yeshu = (int) Math. ceil (1.0 * hangshu/meiyegeshu); // obtain the upper limit conn. close (); return yeshu;} // return public ArrayList <Fruit> selest (int yaozhaoyeshu, int meiyegeshu) of the specified page) throws Exception {ArrayList <Fruit> list = new ArrayList <Fruit> (); String SQL = "select * from fruit limit ?,? "; Pre = conn. prepareStatement (SQL); pre. setInt (1, meiyegeshu * (yaozhaoyeshu-1); // The page on which you want to find the number of rows starting with pre. setInt (2, meiyegeshu); // number of rows on the page to be queried rs = pre.exe cuteQuery (); while (rs. next () {Fruit data = new Fruit (); data. setIds (rs. getString (1); data. setName (rs. getString (2); data. setPrice (rs. getDouble (3); data. setSource (rs. getString (4); data. setNumbers (rs. getInt (5); data. setImage (rs. getString (6); list. add (data);} conn. close (); return list ;}}