Solution for Stored proc automation with output parameters throwing error : Error converting data type nvarchar to int
is Given Below:
I have a stored procedure
declare @p8 int
set @p8=0
declare @p9 varchar(255)
set @p9=''
exec dbo.pr_OAI_HWINTERFACE_LOG_ins @chvOperationGroupID='2445d952-3f55-49da-b067-73e218b102b3',@chvMessage="Bumping Unauthorized Spots",@dtmTargetDate="2021-06-08 00:00:00",@intOperationID=1,@intInserterID=7,@chvStatus="Started",@intDebugLevel=default,@[email protected] output,@[email protected] output
select @p8, @p9
go
Tried automating it but it keeps throwing me error com.microsoft.sqlserver.jdbc.SQLServerException: Error converting data type nvarchar to int.
Passing the JDBC connection and tried everything but just doesn’t work. Keeps throwing the same error
I don’t know what wrong am I doing
public String executeStoredProcedure(Connection con) throws SQLException {
String columnValue = null;
ResultSet resultSet = null;
CallableStatement cstmt = con.prepareCall("{call MediaStar.dbo.pr_OAI_HWINTERFACE_LOG_ins(?, ?, ?, ?, ?, ?, ?, ?, ?)}");
cstmt.setString(1, "2445d952-3f55-49da-b067-73e218b102b3");
cstmt.setString(2, "Bumping Unauthorized Spots");
cstmt.setString(3, "2021-06-08 00:00:00");
cstmt.setInt(4, 1);
cstmt.setInt(5, 7);
cstmt.setString(6, "Started");
cstmt.setString(7, "default");
cstmt.registerOutParameter(8, Types.INTEGER);
cstmt.registerOutParameter(9, Types.VARCHAR);
cstmt.execute();
int status = cstmt.getInt(8);
if (resultSet != null) {
try {
resultSet.next();
columnValue = resultSet.getString(8);
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println( "Value from the DB: " + columnValue);
return columnValue;
}