aspose file tools*
The moose likes JDBC and the fly likes Facing problem when using CallableStatement execute() api Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Facing problem when using CallableStatement execute() api" Watch "Facing problem when using CallableStatement execute() api" New topic
Author

Facing problem when using CallableStatement execute() api

Maya Dolas
Greenhorn

Joined: Jul 04, 2007
Posts: 26
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?


<b><i>Maya</i></b>
Sisir Chanda
Greenhorn

Joined: Jan 03, 2005
Posts: 11
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

Joined: Jul 04, 2007
Posts: 26
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

Joined: Dec 20, 2006
Posts: 2495
    
    8

Should you not write:


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Facing problem when using CallableStatement execute() api