I Have a PL/SQL function which is taking 3 parameters and returning boolean
Below is the part of code snipp
CREATE OR REPLACE FUNCTION IS_EMPLOYEE_EXISTS(
EMP_ID IN EMPLOYEE.EMP_ID%TYPES
EMP_NAME IN EMPLOYEE.EMP_NAME%TYPES
EMP_CATEGORY IN EMPLOYEE.EMP_CATEGORY%TYPES)
RETURN BOOLEAN
-- performing some operations based on the inputs given
Now my task is to call this function from my java class using spring jdbc
I am not able to call this as Jdbc drivers don’t support pl/sql boolean types
my approach of calling this function is as below
I want to call this with named parameters not with the ordinal param
`
@Component
public MyClassDao extends AbstractDao(have the logic to get the DS){
final NamedParameterJdbcTemplete templete;
@Autowired
public MyClassDao(DataSource ds, NamedParameterJdbcTemplete templete){
super(dataSource);
this.templete = templete;
}
String queryString = "{ :"+ "RETURN_VALUE"+ " = call IS_EMPLOYEE_EXISTS ( :" + "EMP_ID" + ", :" +" EMP_NAME" + ", :" + "EMP_CATEGORY" +")}";
public Boolean callFunction(String empId,String empName, String empCat){
boolean result = false;
try ( CallableStatement stmt = getDataSource().getConnection().prepareCall(IS_EMPLOYEE_EXISTS)) {
stmt.registerOutParameter(RETURN_VALUE, Types.NUMERIC);
stmt.setString(EMP_ID, empId);
stmt.setString(EMP_NAME, empName);
stmt.setString(EMP_CATEGORY, empCat);
stmt.execute();
int returnValue = stmt.getInt(RETURN_VALUE);
result = (returnValue == 1); // Interpret as boolean (1 for true, 0 for false)
} catch (SQLException ex) {
ex.printStackTrace();
}
return result;
}
}
I have tried some other approaches also which are also not working out
`