DROP TABLE IF EXISTS' student ';CREATE TABLE' student ' (' ID ')int( One) not NULLauto_increment, ' name 'varchar(255) not NULL, ' Pass 'varchar(255) not NULL, ' sex 'varchar(255) not NULL, ' age 'int( One) not NULL, ' address 'varchar(255)DEFAULT NULL, PRIMARY KEY(' id ')) ENGINE=InnoDB auto_increment=3 DEFAULTCHARSET=UTF8;-- ------------------------------Records of Student-- ----------------------------INSERT into' Student 'VALUES('1','Zhang 31','111','male',' +','Shiyan, Hubei province');INSERT into' Student 'VALUES('2','Lee 42','123','male',' +','Jingan, Shanghai city');INSERT into' Student 'VALUES('3','Zhang 33','111','male',' +','Shiyan, Hubei province');INSERT into' Student 'VALUES('4','Lee 44','123','male',' +','Jingan, Shanghai city');INSERT into' Student 'VALUES('5','Zhang 35','111','male',' +','Shiyan, Hubei province');INSERT into' Student 'VALUES('6','Lee 46','123','male',' +','Jingan, Shanghai city');INSERT into' Student 'VALUES('7','Zhang 37','111','male',' +','Shiyan, Hubei province');INSERT into' Student 'VALUES('8','Lee 48','123','male',' +','Jingan, Shanghai city');INSERT into' Student 'VALUES('9','Zhang 39','111','male',' +','Shiyan, Hubei province');INSERT into' Student 'VALUES('Ten','Lee 40','123','male',' +','Jingan, Shanghai city');
I. Querying 5~10 data
MySQL Paging query:
SELECT * FROM student limit 5, 10;
Oracle Paging query:
SELECT * FROM (select *,rownum rn from student) where RN between 6 and 10;
SQL Server Paging query:
Select Top * from student where ID not in (the SELECT Top 5 ID from the student Order by ID) the order by ID;
DB2 Paging Query:
SELECT * FROM (select *,rownumber () + () as rownum from student) where RN between 6 and 10;
Two. JDBC Link Database code
1.JDBC link MySQL
Packagecom.zjl.db;Importjava.sql.Connection;ImportJava.sql.DriverManager;ImportJava.sql.ResultSet;Importjava.sql.SQLException;Importjava.sql.Statement; Public classDbutils {Private Static FinalString url= "Jdbc:mysql://localhost:3306/databasename?useunicode=true&characterencoding=utf-8"; Private Static FinalString user= "Root"; Private Static FinalString password= "PASSWORD"; Static{ Try{class.forname ("Com.mysql.jdbc.Driver"); } Catch(ClassNotFoundException e) {e.printstacktrace (); } } Public StaticConnection getconnection ()throwssqlexception{returndrivermanager.getconnection (URL, USER, PASSWORD); } //Close Method Public Static voidClose (ResultSet RS, Statement Stat, Connection conn)throwssqlexception{if(rs!=NULL) {rs.close (); }if(stat!=NULL) {stat.close (); }if(conn!=NULL) {conn.close (); } } }
2.JDBC Link Oracle Database
PackageCom.zjl.db;importJava.sql.connection;importJava.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); }//Close method 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 ();}}}
/span>
MySQL Database paging query, Oracle database paging query, SQL Server database paging