JDBC-ORACLE10g BUG

 [From]: http://www.thatisjava.com/jdbc/69759/

The actual problem I have is not to get the update counts.

After several test case scenarios, I found out some interesting facts.

1. As I said in the beginning of my thread, As per the the API, the executeUpdate() method returns either "the row count for INSERT, UPDATE, or DELETE statements or 0 for SQL statements that return nothing" .

The executeUpdate() would return the rowCount only for the PreparedStatement and Statement. Although the CallableStatement extends the executeUpdate() of the Statement Interface, this would not return a rowCount, even if the call to the procedure makes several updates/inserts in the database. The executeStatement() on the callableStatement would return 1 if there was an OUT parameter inside the called Procedure, else it would return 0.

2. We were writing our logic based on this return Value as below:

int primaryId = Obj.getPrimaryId();
  returnValue = p_CallStmt.executeUpdate();
  if(returnValue != 0){// If the procedure has an OUT Parameter primaryId = p_CallStmt.getInt(1);
 // This is the OUT Parameter returned by the Procedure}else{//if no OUT parameter, return a default key value} return primaryId;


3. Everything was fine with 9i Drivers. When no OUT parameter was returned, the executeUpdate() returned 0 and the control goes into the else loop returning default value.
In 10g JDBC Drivers, the executeUpdate() always returns 1. So even if there was no OUT parameter from the Procedure, the program still tries to get p_CallStmt.getInt(1) and throws a NullPointerException.

The solution I came up with was to register the OUT parameter even if you don't
have an OUT parameter. This would give us the required primaryId which we passed to the procedure. sometimes, if the primaryId gets changed in the procedure, it will be returned through the OUT parameter.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值