1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

JDBC Tutorials

Reading an Oracle ARRAY from a stored procedure as an out ?

ORCALE code :
Step 1. Create a Object in Oracle
CREATE OR REPLACE
TYPE test.EMP_TYPE IS OBJECT (
join_date DATE,
emp_name VARCHAR2(200)
)
Step 2. Create ORACLE ARRAY
CREATE OR REPLACE
TYPE test.EMP_ARRAY AS VARYING ARRAY (5000) OF EMP_TYPE;
Step 3.
Create Stored procedure
CREATE OR REPLACE PACKAGE test.EMP_TEST AS
PROCEDURE EMP_RET (p_val            IN OUT    NOCOPY EMP_ARRAY
}
// So what ever you want and store the data into the Array.
Java Code :
OracleCallableStatement ocs = null;
ResultSet rs = null;
//Prepare statement and array
ocs = (OracleCallableStatement) conn.prepareCall({?CALL EMP_TEST. EMP_RET(?)?);
ArrayDescriptor ad = null;
ad = new ArrayDescriptor(?EMP_ARRAY?, conn);
ARRAY emp_aa = new ARRAY(ad, conn, null);
ocs.setArray(1, emp_aaa);
ocs.registerOutParameter(1,OracleTypes.ARRAY,?EMP_ARRAY?);
ocs.execute();
ARRAY array = (ARRAY) ocs.getArray(1);
if (array != null && array.length() > 0) {
rs = array.getResultSet();
}
while (rs.next()) {
STRUCT rowStruct = (STRUCT) rs.getObject(1);
Object[] cols = rowStruct.getAttributes();
System.out.println(cols[1]);//for join_date
System.out.println(cols[2]); // for emp_name
}

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy