Copy codeThe Code is as follows:
Import java. SQL. CallableStatement;
Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. ResultSet;
Import java. SQL. SQLException;
Import java. SQL. Statement;
Public class TestPage {
Public TestPage (){
}
Public static void main (String [] args ){
String driver = "oracle. jdbc. driver. OracleDriver ";
String strUrl = "jdbc: oracle: thin: @ localhost: 1521: xmgl ";
String username = "xmgl ";
String password = "xmgl ";
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;
Try {
Class. forName (driver );
Conn = DriverManager. getConnection (strUrl, username, password );
System. out. println ("OK ");
CallableStatement cs = null;
// Create CallableStatement
Cs = conn. prepareCall ("{call page. fenye (?,?,?,?,?,?)} ");
Cs. setString (1, "mytest"); // table name
Cs. setInt (2, 3); // display several records
Cs. setInt (3, 1); // page number
// Register the total number of records and declare the type of output parameters
Cs. registerOutParameter (4, oracle. jdbc. OracleTypes. INTEGER );
// Total number of registered pages
Cs. registerOutParameter (5, oracle. jdbc. OracleTypes. INTEGER );
// Register the returned result set
Cs. registerOutParameter (6, oracle. jdbc. OracleTypes. CURSOR );
Cs.exe cute ();
// Retrieve the total number of records/Note that 4 in getInt (4) is determined by the position of this parameter.
Int rowNum = cs. getInt (4); // obtain the output parameter
Int pageCount = cs. getInt (5 );
Rs = (ResultSet) cs. getObject (6 );
System. out. println ("rowNum =" + rowNum );
System. out. println ("Total number of pages =" + pageCount );
While (rs. next ()){
System. out. println ("No.:" + rs. getInt (1) + "name:" + rs. getString (2) + "Password:" + rs. getString (3 ));
}
} Catch (SQLException ex2 ){
Ex2.printStackTrace ();
} Catch (Exception ex2 ){
Ex2.printStackTrace ();
} Finally {
Try {
If (rs! = Null ){
Rs. close ();
If (stmt! = Null ){
Stmt. close ();
}
If (conn! = Null ){
Conn. close ();
}
}
} Catch (SQLException ex1 ){
}
}
}
}