• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Facing problem when using CallableStatement execute() api

 
Maya Dolas
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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?
 
Sisir Chanda
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should you not write:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic