梦幻之旅

DEBUG - 天道酬勤

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  671 随笔 :: 6 文章 :: 256 评论 :: 0 Trackbacks
有返回值的存储过程的调用方法如下:
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();
            }

        }

    }

}
posted on 2007-12-18 20:03 HUIKK 阅读(432) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: