vijay ingle

vijay ingle

  • NA
  • 2
  • 648

Not able to print the value of multiple refcursor.

Aug 29 2019 8:27 AM
Not able to print the value of multiple refcursor in .net.
 
procedure :
  1. CREATE OR REPLACE PROCEDURE getEmpNames  
  2. (  
  3. commissioned IN OUT SYS_REFCURSOR,  
  4. salaried IN OUT SYS_REFCURSOR  
  5. )  
  6. IS  
  7. BEGIN  
  8. OPEN commissioned FOR SELECT ename FROM emp WHERE comm is NOT NULL;  
  9. OPEN salaried FOR SELECT ename FROM emp WHERE comm is NULL;  
  10. END;  
.net code
  1. public void RefCursorSample(Connection con)  
  2. {  
  3. try  
  4. {  
  5. con.setAutoCommit(false);  
  6. String commandText = "{call getEmpNames(?,?)}";  
  7. CallableStatement stmt = con.prepareCall(commandText);  
  8. stmt.setNull(1, Types.REF);  
  9. stmt.registerOutParameter(1, Types.REF);  
  10. stmt.setNull(2, Types.REF);  
  11. stmt.registerOutParameter(2, Types.REF);  
  12. stmt.execute();  
  13. ResultSet commissioned = (ResultSet)stmt.getObject(1);  
  14. System.out.println("Commissioned employees:");  
  15. while(commissioned.next())  
  16. {  
  17. System.out.println(commissioned.getString(1));  
  18. }  
  19. ResultSet salaried = (ResultSet)stmt.getObject(2);  
  20. System.out.println("Salaried employees:");  
  21. while(salaried.next())  
  22. {  
  23. System.out.println(salaried.getString(1));  
  24. }  
  25. }  
  26. catch(Exception err)  
  27. {  
  28. System.out.println("An error has occurred.");  
  29. System.out.println("See full details below.");  
  30. err.printStackTrace();  
  31. }  
  32. }  

Answers (3)