我正在使用带有SQL Server 2005的Microsoft JDBC Driver 2.0。为了更好地解释我的问题,让我从一个示例代码开始调用存储过程。
public static void executeSproc(Connection con)
{
CallableStatement cstmt = con.prepareCall("{call dbo.getEmployeeManagers(?)}");
cstmt.setInt(1, 50);
ResultSet rs = cstmt.executeQuery();
while (rs.next()) {
// print results in the result set
}
rs.close();
cstmt.close();
}
使用SQL事件探查器我看到JDBC驱动程序生成以下sql语句来进行调用 -
declare @P1 int
set @P1=1
exec sp_prepexec @P1 output, N'@P0 int', N'EXEC getEmployeeManagers @P0', 50
select @P1
所以这意味着当我使用CallableStatement执行存储过程时,sp_prepexec
声明被称为。后来当我结束陈述时,sp_unprepare
叫做。这似乎是JDBC驱动程序的默认行为。该
问题是,生成预准备语句然后关闭它的开销
有性能影响。有没有办法让驱动程序执行存储
程序直接?为什么司机不能这样做 -
exec getEmployeeManagers @P0=50