This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling Oracle Function that returns %ROWTYPE

 
chris snyder
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are trying to call the following Oracle Function (8.1.6)
/*The package declaration*/
PACKAGE ACCOUNTSPKG IS
FUNCTION FINDRECORD
(P_ID IN accounts.id%TYPE
)
RETURN accounts%ROWTYPE;
END ACCOUNTSPKG;
Notice that the return is NOT a REF CURSOR. I have not been able to get this to work and haven't seen any examples that only return %ROWTYPE. How do you call (prepareCall("xxx")) this Function, and how do you get the resultset? [See code below]
// Begin Code
try
{
conn = DBUtil.getConnection(Constants.IPRO_DS);
// .prepareCall line throws SQL Exception:
// java.sql.SQLException: Invalid column
// type Account Info
call = conn.prepareCall (
"{ ? = call AccountsPkg.FindRecord (?)}");
call.registerOutParameter(1, OracleTypes.CURSOR);
call.setInt(2, 10);
call.execute();
ResultSet rs = (ResultSet) call.getObject(1);

while(rs != null && rs.next())
{
result += "\n AccountID: " + rs.getInt("ID")
+ "Account Type: " + rs.getString("ACCOUNT_TYPE");
}
call.close();
conn.close();

}
catch(Exception e)
{
System.out.println("AccountDAO.getAccountRS() exception: " + e);
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic