【问题标题】:Overhead with Microsoft JDBC driver when executing a stored procedure执行存储过程时使用 Microsoft JDBC 驱动程序的开销
【发布时间】: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


    【解决方案1】:

    尝试使用 SQLServer 的 jTDS 驱动程序。我在工作中使用它,它似乎比MS提供的驱动好很多。

    【讨论】:

      猜你喜欢
      • 2015-11-24
      • 2017-06-17
      • 2020-06-13
      • 2013-08-12
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 2017-01-09
      • 1970-01-01
      相关资源
      最近更新 更多