Monday, June 23, 2014

Use cursor to fetch data in java

Suppose following table is present in the database:
Queue (id NUMBER(10),email1 VARCHAR2(100), email2 VARCHAR2(100),head VARCHAR2(200),body VARCHAR2(1000));


In the backend package can be defined as 

CREATE OR REPLACE PACKAGE GetRefCursors1 IS
TYPE csGetResultSet is REF CURSOR;
function sfGetAccountInterval1
return csGetResultSet;

end GetRefCursors1;


CREATE OR REPLACE package body GetRefCursors1 is
function sfGetAccountInterval1
return csGetResultSet is

csGetAccounts csGetResultSet;

begin

open csGetAccounts for

SELECT Queue.id,Queue.email1,Queue.email2,Queue.head,Queue.body
FROM Queue
ORDER BY Queue.id ;

return csGetAccounts;

end sfGetAccountInterval1;

end GetRefCursors1;

This function will return a cursor which can be used in the java program to access backend data

#Check next post to get handling of cursor in java program

No comments:

Post a Comment