简体   繁体   中英

Spring JdbcTemplate is extremely slow when call SQLserver Stored procedure

I'm using JdbcTemplate.execute() to call a SP connected with SQLServer database. 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.

Note the stored procedure contains "SET ANSI_NULLS ON" and "SET QUOTED_IDENTIFIER ON"

After some testing I finally find that the issue lies on blank values judgement in my 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM