MySQL資料庫分頁查詢,Oracle資料庫分頁查詢,SqlServer資料庫分頁

來源:互聯網
上載者:User

標籤:get   manager   str   static   print   odi   varchar   val   util   

DROP TABLE IF EXISTS `student`;CREATE TABLE `student` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `name` varchar(255) NOT NULL,  `pass` varchar(255) NOT NULL,  `sex` varchar(255) NOT NULL,  `age` int(11) NOT NULL,  `address` varchar(255) DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;-- ------------------------------ Records of student-- ----------------------------INSERT INTO `student` VALUES (‘1‘, ‘張三1‘, ‘111‘, ‘男‘, ‘21‘, ‘湖北省十堰市‘);INSERT INTO `student` VALUES (‘2‘, ‘李四2‘, ‘123‘, ‘男‘, ‘21‘, ‘上海市靜安區‘);INSERT INTO `student` VALUES (‘3‘, ‘張三3‘, ‘111‘, ‘男‘, ‘21‘, ‘湖北省十堰市‘);INSERT INTO `student` VALUES (‘4‘, ‘李四4‘, ‘123‘, ‘男‘, ‘21‘, ‘上海市靜安區‘);INSERT INTO `student` VALUES (‘5‘, ‘張三5‘, ‘111‘, ‘男‘, ‘21‘, ‘湖北省十堰市‘);INSERT INTO `student` VALUES (‘6‘, ‘李四6‘, ‘123‘, ‘男‘, ‘21‘, ‘上海市靜安區‘);INSERT INTO `student` VALUES (‘7‘, ‘張三7‘, ‘111‘, ‘男‘, ‘21‘, ‘湖北省十堰市‘);INSERT INTO `student` VALUES (‘8‘, ‘李四8‘, ‘123‘, ‘男‘, ‘21‘, ‘上海市靜安區‘);INSERT INTO `student` VALUES (‘9‘, ‘張三9‘, ‘111‘, ‘男‘, ‘21‘, ‘湖北省十堰市‘);INSERT INTO `student` VALUES (‘10‘, ‘李四0‘, ‘123‘, ‘男‘, ‘21‘, ‘上海市靜安區‘);

 

一.查詢5~10條資料

mysql分頁查詢:

select * from student limit 5,10; 

 

oracle分頁查詢:

select * from (select *,rownum rn from student )where rn between 6 and 10;

 

sqlserver分頁查詢:

select top 10 * from student  where  id not in(select  top 5 id from student order by id ) order by id ;

 

DB2分頁查詢:

select * from (select *,rownumber() over() as  rownum  from student )where rn between 6 and 10;

 

二.jdbc連結資料庫代碼

 1.jdbc連結mysql

package com.zjl.db;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class DbUtils {        private  static  final String URL="jdbc:mysql://localhost:3306/DataBaseName?useUnicode=true&characterEncoding=utf-8";                  private  static  final String USER="root";    private  static  final String PASSWORD="password";        static{          try {                Class.forName("com.mysql.jdbc.Driver");                           } catch (ClassNotFoundException e) {               e.printStackTrace();           }    }            public static Connection getConnection() throws SQLException{        return DriverManager.getConnection(URL, USER, PASSWORD);    }        //關閉方法    public  static void close(ResultSet rs, Statement stat, Connection conn) throws SQLException{        if(rs!=null){            rs.close();        }if(stat!=null){            stat.close();        }if(conn!=null){            conn.close();        }    }        }    

2.jdbc連結oracle資料庫

package com.zjl.db;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class DbUtils {        private  static  final String URL="jdbc:oracle:thin:@192.168.0.1:1521:DataBaseName?useUnicode=true&characterEncoding=utf-8";              private  static  final String USER="root";    private  static  final String PASSWORD="password";        static{          try {                Class.forName("oracle.jdbc.driver.OracleDriver");                           } catch (ClassNotFoundException e) {               e.printStackTrace();           }    }            public static Connection getConnection() throws SQLException{        return DriverManager.getConnection(URL, USER, PASSWORD);    }        //關閉方法    public  static void close(ResultSet rs, Statement stat, Connection conn) throws SQLException{        if(rs!=null){            rs.close();        }if(stat!=null){            stat.close();        }if(conn!=null){            conn.close();        }    }        }    

MySQL資料庫分頁查詢,Oracle資料庫分頁查詢,SqlServer資料庫分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.