Java call Oracle Paging stored procedure sample _java

Source: Internet
Author: User

1. Page-type

Copy Code code as follows:

Package org.zh.basic;

/**
* Page class
*
* @author Keven
*
*/
public class PageInfo {

Defined
Private String P_tablename; -Table Name
Private String P_strwhere; --Query criteria
Private String P_ordercolumn; --Sorted columns
Private String P_orderstyle; --Sort the way
private int p_curpage; --Current page
private int p_pagesize; --Display the number of record bars per page
private int p_totalrecords; --Total number of records
private int p_totalpages; --Total Pages

   ///<summary>
   ///define Functions
   ///</summary>< br>    public PageInfo () {
   }

    public PageInfo (String p_tablename, String p_strwhere,
             string P_ordercolumn, string p_orderstyle, int p_curpage,
             int p_pagesize, int p_totalrecords, int p_totalpages) {
         this.p_tablename = p_tablename;
        this.p_strwhere = p_strwhere;
        this.p_ordercolumn = p_ordercolumn;
        this.p_orderstyle = P_orderstyle;
        this.p_curpage = p_curpage;
        this.p_pagesize = p_pagesize;
        this.p_totalrecords = p_totalrecords;
        this.p_totalpages = p_totalpages;
   }

Public String Getp_tablename () {
return p_tablename;
}

public void Setp_tablename (String ptablename) {
P_tablename = Ptablename;
}

Public String Getp_strwhere () {
return p_strwhere;
}

public void Setp_strwhere (String pstrwhere) {
P_strwhere = Pstrwhere;
}

Public String Getp_ordercolumn () {
return p_ordercolumn;
}

public void Setp_ordercolumn (String pordercolumn) {
P_ordercolumn = Pordercolumn;
}

Public String Getp_orderstyle () {
return p_orderstyle;
}

public void Setp_orderstyle (String porderstyle) {
P_orderstyle = Porderstyle;
}

public int getp_curpage () {
return p_curpage;
}

public void setp_curpage (int pcurpage) {
P_curpage = Pcurpage;
}

public int getp_pagesize () {
return p_pagesize;
}

public void setp_pagesize (int ppagesize) {
P_pagesize = ppagesize;
}

public int getp_totalrecords () {
return p_totalrecords;
}

public void setp_totalrecords (int ptotalrecords) {
P_totalrecords = Ptotalrecords;
}

public int getp_totalpages () {
return p_totalpages;
}

public void setp_totalpages (int ptotalpages) {
P_totalpages = ptotalpages;
}

}

2 Call

Copy Code code as follows:

Package org.zh.sys.server;

Import java.sql.CallableStatement;
Import java.sql.Connection;
Import Java.sql.ResultSet;
Import Java.sql.ResultSetMetaData;
Import java.sql.SQLException;
Import java.util.ArrayList;
Import Java.util.Map;
Import Java.util.HashMap;
Import org.hibernate.Session;
Import Org.zh.basic.PageInfo;
Import Org.zh.dao.HibernateSessionFactory;
Import Oracle.jdbc.driver.OracleTypes;
Import oracle.jdbc.OracleCallableStatement;


public class Generatepage {

Public Generatepage () {

}

public static ArrayList Prc_page (PageInfo Page) {
ArrayList list = new ArrayList ();
MAP MP;
session s = NULL;
Connection conn = null;
ResultSet rs = null;
callablestatement proc = null;
try {
s = hibernatesessionfactory.getsession ();
conn = S.connection ();
proc = Conn.preparecall ("{Call Pages.prc_page (?,?,?,?,?,?,?,?,?)}");
Proc.setstring (1, Page.getp_tablename ());
Proc.setstring (2, Page.getp_strwhere ());
Proc.setstring (3, Page.getp_ordercolumn ());
Proc.setstring (4, Page.getp_orderstyle ());
Proc.setint (5, Page.getp_curpage ());
Proc.setint (6, Page.getp_pagesize ());
Proc.registeroutparameter (7, Oracletypes.number);
Proc.registeroutparameter (8, Oracletypes.number);
Proc.registeroutparameter (9, oracletypes.cursor);
Proc.execute ();
Page.setp_totalrecords (Proc.getint ("p_totalrecords"));
Page.setp_totalpages (Proc.getint ("p_totalpages"));
List = (ArrayList) proc.getobject ("V_cur");
Page.setp_totalrecords (Proc.getint (7));
Page.setp_totalpages (Proc.getint (8));
rs = ((oraclecallablestatement) proc). GetCursor (9); Get output Result set parameter
ResultSetMetaData RSMD = Rs.getmetadata ();
int numberofcolumns = Rsmd.getcolumncount ();
while (Rs.next ()) {
MP = new HashMap (numberofcolumns);
for (int r = 1; r < NumberOfColumns; r++) {
Mp.put (Rsmd.getcolumnname (R), Rs.getobject (R));
}
List.add (MP);
}
return list;
catch (SQLException ex) {
Ex.printstacktrace ();
return list;
catch (Exception ex2) {
Ex2.printstacktrace ();
return list;
finally {
try {
if (proc!= null) {
Proc.close ();
}
if (Rs!= null) {
Rs.close ();
}
IF (conn!= null) {
Conn.close ();
}
catch (SQLException Ex1) {
Ex1.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.