• 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

Facing problem when using CallableStatement execute() api

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I created and executed following Oracle procedure, I am using Oracle 10g.

CREATE OR REPLACE PROCEDURE emp_info (emp_ref_cursor01 OUT SYS_REFCURSOR)
IS

BEGIN
OPEN emp_ref_cursor02 FOR
SELECT empno, lastname, salary FROM EMPLOYEE;
END;
/

I am invoking the above procedure in my java code using JDBC CallableStatement

CallableStatement cStmt = conn.prepareCall("begin emp_info(?); end;");
cStmt.registerOutParameter(1, OracleTypes.CURSOR);

After this i wrote,

boolean executed = cStmt.execute();
System.out.println(executed);
ResultSet rs= cStmt.getResultSet();

and the value of executed is FALSE & the resultset rs is NULL.

However when I use the following

ResultSet rset = (ResultSet) cStmt.getObject(1);

I get the resultset object and can even iterate over it and get the desired results.

Why is the execute() not returning me the resultset?
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in case of CallableStatement, execute() method does now execute any SQL, rather it executes PL/SQL procedure/function. In this case, CallableStatement.execute() neither have ResultSet within the CallableStatement nor an UpdateCount. You should retrieve the out parameter using CallableStatement.getXXX() method. That is why you are having FALSE return value and the returned resultset is NULL.

Hopefully this clarifies your query.
 
Maya Dolas
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so does it mean that the execute() method of CallableStatement is just for merely executing stored procedures or functions and the return type doesn't matter or never used. Aren't there any use-cases where one needs to check the status of execute method and then decide further proceedings?
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should you not write:
 
reply
    Bookmark Topic Watch Topic
  • New Topic