Oracle uses the in-row view for paging display

Source: Internet
Author: User

The temp table has 94 data records in the above structure.

Pagedemo. Java:

Public class pagedemo {public static void main (string [] ARGs) {consumer SC = new consumer (system. in); While (true) {int page = SC. nextint (); getresult (PAGE) ;}} public static int gettotalcount () {// calculate the total number of records in the data table. Int n =-1; connection conn = NULL; statement stmt = NULL; string SQL = "select count (*) Nums from temp"; try {class. forname ("oracle. JDBC. driver. oracledriver "); Conn = drivermanager. getconnection ("JDBC: oracle: thin: @ local HOST: 1521: orcl "," Scott "," Tiger "); stmt = Conn. createstatement (); resultset rs1_stmt.exe cutequery (SQL); RS. next (); n = Rs. getint ("Nums");} catch (classnotfoundexception e) {e. printstacktrace ();} catch (sqlexception e) {e. printstacktrace ();} return N;} public static int gettotalpages () {// 10 records are displayed on each page. Int totalcount = gettotalcount (); int pages = 0; if (totalcount % 10 = 0) {pages = totalcount/10;} else {pages = totalcount/10 + 1;} re Turn pages;} public static void getresult (INT page) {int from = (page-1) * 10 + 1; int to = from + 10; connection conn = NULL; preparedstatement pstmt = NULL; string SQL = "select ID, question, RN" + "from" + "(select ID, question, rownum rn from temp where rownum <?) "+" Where rn >=? "; Try {class. forname ("oracle. JDBC. driver. oracledriver "); Conn = drivermanager. getconnection ("JDBC: oracle: thin :@ localhost: 1521: orcl", "Scott", "Tiger"); pstmt = Conn. preparestatement (SQL); pstmt. setint (1, to); pstmt. setint (2, from); resultset rs1_pstmt.exe cutequery (); While (RS. next () {system. out. println (RS. getint ("ID") + ":" + Rs. getstring ("Question");} catch (classnotfoundexception e) {e. printstacktrace ();} catch (sqlexception e) {e. printstacktrace ();}}}

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.