I have code stored procedure that returns sysrefcursor as the OUT 开发者_运维知识库parameter.
CREATE OR REPLACE PROCEDURE report (rvdate IN VARCHAR2,RESULTSET OUT NOCOPY sys_refcursor)
AS
..
...
.
OPEN RESULTSET FOR (SELECT A.* FROM TEMP_DATA )
...
..
CLOSE RESULTSET
END;
/
Calling this procedure from ibatis xml configuration
<parameterMap id="inputParam" class="map">
<parameter property="date" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
<parameter property="output" javaType="java.sql.ResultSet" jdbcType="ORACLECURSOR" resultMap="rec-map" mode="OUT"/>
</parameterMap>
<procedure id="readReport" parameterMap="inputParam" >
<![CDATA[{ call report(?,?) } ]]>
</procedure>
And in java i am doing this
java.util.Map map = new java.util.HashMap();
map.put("date", date);
System.out.println("date" + date);
xmlconfig.queryForObject("readReport", map);
return (List)map.get("output");
The above code returns RESULTSET cursor , if i close this cursor then it throws a exception at the java end.anybody help me on whether to close the RESULTSET or not ..
Update :
Do i need to close the oracle cursor in java or in ibatis xml.
"anybody help me on whether to close the RESULTSET or not"
Don't close it in the stored procedure.
A Ref Cursor is a pointer; closing the cursor variable releases the memory. Hence your java code hurls an exception.
All your stored procedure needs to do is open the ref cursor and assign it to the OUT parameter. Let your java code handle the closure (after it has fetched all the data, obviously).
"Do i need to close the oracle cursor in java or in ibatis xml."
I'm not familiar with Ibatis but the examples I have seen from Googling the topic suggest that the queryForObject()
call handles the cursor. Not that I have found any actual documentation stating this is so, I'm just inferring from the absence of any mention of closure.
精彩评论