有返回值的存储过程的调用方法如下:

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();
}
}
}
}




































































