【发布时间】:2009-05-28 21:04:53
【问题描述】:
我正在使用带有 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 Profiler 我看到 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
【问题讨论】:
标签: java sql-server-2005 jdbc