JSP page (Database reads data)

Source: Internet
Author: User
<% @ Page contenttype = "text/html; charset = gb2312" %> <% @ page Language = "Java" %> <% @ page import = "Java. SQL. * "%> <% // driver name, which is old. If you use mysql5, change it by yourself. String drivername = "org. gjt. mm. mySQL. driver "; string username =" root "; // database username string userpasswd =" 666666 "; // password string dbname =" Search "; // database name string tablename = "organizations"; // table name // connection string url = "JDBC: mysql: // localhost/" + dbname + "? User = "+ username +" & Password = "+ userpasswd; Class. forname (drivername ). newinstance (); connection = drivermanager. getconnection (URL); Statement statement = connection. createstatement (); // number of records displayed per page int pagesize = 30; int startrow = 0; // start to display the number of records int pageno = 0; // number of pages to be displayed int counterstart = 0; // The initial value of each page number int counterend = 0; // the maximum value of the displayed page number int recordcount = 0; // The total number of records; int maxpage = 0; // total number of pages int prevstart = 0 ;/ /INT nextpage = 0 on the previous page; // int lastrec = 0 on the next page; int laststartrecord = 0; // The number of records displayed on the last page. // obtain the number of pages to be displayed, if (request. getparameter ("pageno") = NULL) {// if it is null, it indicates page 1st if (startrow = 0) {pageno = startrow + 1; // set to 1} else {pageno = integer. parseint (request. getparameter ("pageno"); // obtain the number of pages submitted by the user. startrow = (pageno-1) * pagesize; // obtain the record number displayed at the beginning} // because the number of displayed page numbers changes dynamically, it is impossible to display one hundred links at the same time if there are 100 pages in total. Instead, the initial value of the displayed page number is displayed based on the current page number. // a certain number of page links are displayed. // the initial value of the displayed page number is displayed !! If (pageno % pagesize = 0) {counterstart = pageno-(pagesize-1);} else {counterstart = pageno-(pageno % pagesize) + 1 ;} counterend = counterstart + (pagesize-1 ); %> <HTML> 
Related Article

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.