How can i pass output associative array of pl/sql to java?
For Nested table i have done it in follwing way? This is pl/sql stored procedure.
CREATE or REPLACE PROCEDURE TEST(
activationStartDate IN DATE,
activationEndDate IN DATE,
deActivationStartDate IN DATE,
deActivationEndDate IN DATE
Out_Entity OUT TEST1.RefCsr
)
AS
FirstNameListTable LIST_TABLE;
{--COMMENT :LIST_TABLE is nested table :create or replace TYPE "LIST_TABLE" as table of varchar2(20);-----Nested Table Declaration
/
}
totalSameFirstName NUMBER;
j NUMBER := 1;
BEGIN
SELECT first_name BULK COLLECT INTO FirstNameListTable FROM Employee where start_date between activationStartDate AND activationEndDate
MINUS
SELECT first_name FROM Employee where start_date between deActivationStartDate AND deActivationEndDate
OPEN Out_Entity FOR SELECT * FROM TABLE(
CAST (开发者_开发百科
FirstNameListTable AS LIST_TABLE
)
) Nos;
END;
/
My JavaCode is
--First getConnection
--prepare sql string : sql = "{ Call Test(?,?,?,?,?) } ";
--Use prepareCall function on Connection object and passed this sql string and retrived CallableStatement class object.
stmt.setTimestamp(1,activationStartDate);
stmt.setTimestamp(2,activationEndDate);
stmt.setTimestamp(3,deActivationStartDate);
stmt.setTimestamp(4,deActivationEndDate);
stmt.registerOutParameter(5,-10);
stmt.execute();
List result = new ArrayList();
ResultSet rs = (ResultSet)stmt.getObject(5);
int i=0;
while (rs.next())
{
System.out.println(i+". "+rs.getString(1));
i++;
}
Then what if i want to select more than one column from EMPLOYEE and pass to my javaCode......How my javaCode and Pl/Sql will look like?
you need to use nest loop
for example in the result set get the column count value
and try like this
List<List> result = new ArrayList()<List>;
List col = new ArrayList();
ResultSet rs = (ResultSet)stmt.getObject(5);
ResultSetMetaData rsMetaData = rs.getMetaData();
int numberOfColumns = rsMetaData.getColumnCount();
while (rs.next())
{
col = new ArrayList();
for(int j=1;j<numberOfColumns;j++)
col.add(rs.getString(j);
result.add(col);
}
here first loop for getting the rows and the nested loop to getting the columns value this value are store in the col list object and need to each time create new object
精彩评论