简体   繁体   English

Spring JdbcTemplate 在调用 SQLserver 存储过程时非常慢

[英]Spring JdbcTemplate is extremely slow when call SQLserver Stored procedure

I'm using JdbcTemplate.execute() to call a SP connected with SQLServer database.我正在使用 JdbcTemplate.execute() 调用与 SQLServer 数据库连接的 SP。 With the same parameters, when I execute the SP directly in SQL Server Management Studio it finishes within 1s, but when I use JdbcTemplate in java it execute over minutes with causes severe performance issue.使用相同的参数,当我直接在 SQL Server Management Studio 中执行 SP 时,它会在 1 秒内完成,但是当我在 Java 中使用 JdbcTemplate 时,它​​会执行几分钟,导致严重的性能问题。

Note the stored procedure contains "SET ANSI_NULLS ON" and "SET QUOTED_IDENTIFIER ON"注意存储过程包含“SET ANSI_NULLS ON”和“SET QUOTED_IDENTIFIER ON”

After some testing I finally find that the issue lies on blank values judgement in my SP:经过一些测试,我终于发现问题出在我的 SP 中的空白值判断上:

I have some default parameters for the SP and set them as @A nvarchar(255)='', then during the logic I need to use them as logic condition: if(@A is not null and rtrim(ltrim(@A)) <>'') Just that simple and it works totally good in the Management Studio.我有一些 SP 的默认参数并将它们设置为 @A nvarchar(255)='',然后在逻辑期间我需要将它们用作逻辑条件: if(@A is not null and rtrim(ltrim(@A) ) <>'') 就这么简单,它在 Management Studio 中运行良好。

After change that init to @A nvarchar(255) and use if(@A is not null), it also returns the results in JdbcTemplate... so there should be some inner logic for JdbcTemplate to do that empty check but I'm not sure why and how.将该 init 更改为 @A nvarchar(255) 并使用 if(@A is not null) 后,它还返回 JdbcTemplate 中的结果...所以 JdbcTemplate 应该有一些内部逻辑来执行空检查,但我是不知道为什么以及如何。

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

相关问题 如何使用JdbcTemplate在spring mvc中对存储过程或函数进行简单调用 - How to make a simple call to a stored procedure or function in spring mvc using JdbcTemplate 使用Spring JdbcTemplate中的调用来调用存储的函数 - Calling stored function using call in Spring JdbcTemplate 使用Spring时取消存储过程调用 - Cancel a stored procedure call when using Spring Spring JdbcTemplate可以等待oracle存储过程完成多长时间 - how long can Spring JdbcTemplate wait for an oracle stored procedure to finish SQLServer 2008:来自JAVA的存储过程调用同时执行插入和更新语句时返回错误 - SQLServer 2008: Stored procedure call from JAVA Returns error when both insert and update statement are executed 使用 Spring JPA 调用存储过程 - Stored procedure call with Spring JPA Java Spring jdbcTemplate queryForList慢 - Java Spring jdbcTemplate queryForList slow 尝试使用Spring JdbcTemplate从Java访问OS400 / DB2存储过程输出参数 - Trying to access OS400/DB2 Stored Procedure Output Parameters from Java with Spring JdbcTemplate 尝试使用Spring JdbcTemplate从Java访问AS400 / DB2存储过程 - Trying to access AS400/DB2 stored procedure from Java with Spring JdbcTemplate 如何使用spring和hibernate调用存储过程 - how to call stored procedure using spring and hibernate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM