`
hwpok
  • 浏览: 242198 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

有返回值 存储过程 的 调用

    博客分类:
  • Java
 
阅读更多
有返回值的存储过程的调用方法如下:
public class SenderPrepareCallProcedure {
    
public String testP(int statusWillSending, int statusNowSending, int fixedSending) {
        String taskId 
= null;
        Connection connection 
= null;
        CallableStatement proc 
= null;
        
try {
            connection 
= DBPool.getConnection();
            proc 
= connection.prepareCall("{call backtrack_taskId(?,?,?,?)}");
            proc.setInt(
1, statusWillSending);
            proc.setInt(
2, statusNowSending);
            proc.setInt(
3, fixedSending);
            proc.registerOutParameter(
4, Types.INTEGER);
            proc.execute();
            taskId 
= String.valueOf(proc.getInt(4));
            
//System.out.println("taskId is: " + taskId);
        }
 catch (Exception e) {
            e.printStackTrace();
        }
 finally {
            
this.freeSource(proc, connection);
        }

        
if(taskId != null && !taskId.equals("0")){
            
return taskId;
        }

        
return null;
    }


    
private void freeSource(CallableStatement proc, Connection connection) {
        
if (proc != null{
            
try {
                proc.close();
            }
 catch (Exception e) {
                e.printStackTrace();
            }

        }

        
if (connection != null{
            
try {
                connection.close();
            }
 catch (Exception e) {
                e.printStackTrace();
            }

        }

    }

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics