aspose file tools*
The moose likes Oracle/OAS and the fly likes Fetching multiple rows through stored procedure by preparecall method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Fetching multiple rows through stored procedure by preparecall method" Watch "Fetching multiple rows through stored procedure by preparecall method" New topic
Author

Fetching multiple rows through stored procedure by preparecall method

Raguraman Thiru
Greenhorn

Joined: Jul 25, 2013
Posts: 5
Hi,

I want to fetch multiple records from a table in a java program. this is what my code :

CREATE OR REPLACE PROCEDURE P_GetIDS
IS
CURSOR c1 IS
SELECT * FROM IDS;
BEGIN
OPEN c1;
END P_GetIDS;
/


Java part:

CallableStatement cs = connection.prepareCall("{call P_GetIDS()}");

ResultSet rs =cs.executeQuery();

while(rs.next()){
// my logic
}


Error im getting:

java.sql.SQLException: Cannot perform fetch on a PLSQL statement: next



Please let me know where im making mistake.

Thanks,
Ragu

Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Hi Ragu,
Your PL/SQL needs to return something.
You have two (2) options:
  • Declare an "out" parameter in your stored procedure.
  • Use a stored function instead of a stored procedure.

  • Your implementation will depend on the version of java you are using, the version of Oracle database you are using and the version of Oracle JDBC driver you are using.
    Unfortunately, I could not ascertain these details from your post.
    I suggest you search the internet for:
    oracle jdbc return ref cursor

    Good Luck,
    Avi.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Fetching multiple rows through stored procedure by preparecall method