• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Fetching multiple rows through stored procedure by preparecall method

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic