[英]Overhead with Microsoft JDBC driver when executing a stored procedure
I am using Microsoft JDBC Driver 2.0 with SQL Server 2005. To explain my question better, let me start with a sample code to call a stored procedure. 我正在使用Microsoft JDBC Driver 2.0和SQL Server 2005.为了更好地解释我的问题,让我从一个示例代码开始调用存储过程。
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();
}
Using SQL Profiler I see that the JDBC driver generates the following sql statements to make the call - 使用SQL事件探查器我看到JDBC驱动程序生成以下sql语句来进行调用 -
declare @P1 int
set @P1=1
exec sp_prepexec @P1 output, N'@P0 int', N'EXEC getEmployeeManagers @P0', 50
select @P1
So this means when I execute a stored procedure using a CallableStatement, the sp_prepexec
statement is called. 所以这意味着当我使用CallableStatement执行存储过程时,会调用sp_prepexec
语句。 And later when I close the statement, the sp_unprepare
is called. 稍后当我关闭语句时,会调用sp_unprepare
。 This seems to be the default behavior of the JDBC driver. 这似乎是JDBC驱动程序的默认行为。 The problem is, the overhead to generate a prepared statement and then close it has performance impact. 问题是,生成预准备语句然后关闭它的开销会对性能产生影响。 Is there a way for the driver to execute the stored procedure directly? 有没有办法让驱动程序直接执行存储过程? Why can't the driver just do this - 为什么司机不能这样做 -
exec getEmployeeManagers @P0=50
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.