Getting below error when I connect a stored procedure using JDBC template in my Spring boot application. Error getting only for the accIds parameter
Resolved [org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback;
uncategorized SQLException for SQL [{call prc_Test(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; SQL state [S0002]; error code [8169]; Conversion failed when converting from a character string to uniqueidentifier.]
Code:
String aa= "aa95dc9c-0c75, b96bc70b-858e";
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate)
.withProcedureName("prc_Test");
Map<String, Object> inParamMap = new LinkedHashMap<String, Object>();
//inParamMap.put("accIds", lst.stream().collect(Collectors.joining(",")));
inParamMap.put("accIds", aa);
This is the stored procedure in the Azure SQL database:
CREATE PROCEDURE [dbo].[prc_Test]
@accIds varchar(max) = '',
@paSize int = 10,
@pagecount int =1,
@isOpenCases bit =1 ,
@comId VARCHAR(MAX)='#',
@casestatus VARCHAR(MAX)='#',
AS
BEGIN
-- .............................
FROM c_test2
WHERE accIds IN (SELECT CAST(value AS uniqueidentifier)
FROM string_split (@accIds,',') )
AND (@comId = '#' OR [test_comp] IN (SELECT VALUE
FROM string_split (@comId,',')))
-- ....................................
-- ....................................
FROM c_test2
WHERE accIds IN (SELECT CAST(value AS uniqueidentifier)
FROM string_split (@accIds,',') )
AND (@comId = '#' OR [test_comp] IN (SELECT VALUE
FROM string_split (@comId,',')))
-- ....................................
-- ....................................
ORDER BY test_data DESC
OFFSET (@pagecount-1) * @pagesize ROWS
FETCH NEXT @pagesize ROWS ONLY
RETURN 0
END
Any idea why the errors occur?
The provided string:
does not contain valid unique identifier numbers. This may be the reason for the error above. You can try the code below to call a stored procedure with valid unique identifiers:
This returns a valid row as shown below: