'How to call multiple sql statements using jdbc template in java
I want to get n values of a sequence at once from SQL server. I am able to achieve this using the below list of SQL queries:
DECLARE @FirstSeqNum sql_variant, @LastSeqNum sql_variant;
EXEC sys.sp_sequence_get_range
@sequence_name = N'SERVICEVRSNS.CountBy1'
, @range_size = 100
, @range_first_value = @FirstSeqNum OUTPUT
, @range_last_value = @LastSeqNum OUTPUT ;
-- The following statement returns the output values
SELECT
@FirstSeqNum AS FirstVal
, @LastSeqNum AS LastVal ;
The output looks something like this:
FirstVal | SecondVal |
---|---|
101 | 200 |
Every time I trigger the above SQL list, it gives the range.
Can I achieve the same using one SQL statement to get the range something like this:
private final JdbcTemplate jdbcTemplate;
jdbcTemplate.queryForObject(sql, Map<String,Object>.class);
Note: I don't want to create a stored procedure or call the system stored procedure.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|