简体   繁体   English

执行存储过程时使用Microsoft JDBC驱动程序的开销

[英]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

Try using the jTDS driver for SQLServer. 尝试使用SQL Server的jTDS驱动程序。 I use it at work and it seems to be a lot better than the driver provided by MS. 我在工作中使用它,它似乎比MS提供的驱动程序好很多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Sybase 存储过程插入限制与 JDBC 驱动程序 - Sybase stored procedure insert limit with JDBC driver 使用Spring JDBC API批量执行存储过程 - Batch executing of stored procedure with Spring JDBC API 尝试执行存储过程时收到“ com.microsoft.sqlserver.jdbc.SQLServerException:索引1超出范围。” - Receiving “com.microsoft.sqlserver.jdbc.SQLServerException: The index 1 is out of range.” when trying to execute stored procedure 从Java执行存储过程,而不是通过JDBC CallableStatement执行存储过程 - Executing stored procedure from Java, other than with JDBC CallableStatement JDBC调用Microsoft SQL Server存储过程的同义词 - JDBC call to a synonym to Microsoft SQL Server stored procedure 执行存储过程时休眠异常 - hibernate exception when executing stored procedure JDBC存储过程调用 - JDBC stored procedure call 在jdbc中调用存储过程 - Calling stored procedure in jdbc PostgreSQL JDBC 驱动程序在执行查询后何时获取行? - When does the PostgreSQL JDBC driver fetch rows after executing a query? Microsoft SQL Server JPA存储过程com.microsoft.sqlserver.jdbc.SQLServerException:'{'附近的语法不正确 - Microsoft SQL Server JPA Stored Procedure com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '{'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM