Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fetching multiple rows through stored procedure by preparecall method

 
Raguraman Thiru
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic