Java MYSQL paging, javamysql Paging

Source: Internet
Author: User

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 ;}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.