I'm working on upgrading the Java version of a project in my company from java 8 to 21. They have this module which was written years back
SimpleJdbcCall simpleJdbcCall;
simpleJdbcCall = new SimpleJdbcCall(new JdbcTemplate(dataSource))
// .withoutProcedureColumnMetaDataAccess()
.withProcedureName(spName);
if (StringUtils.hasText(schema)) {
simpleJdbcCall.setSchemaName(schema);
}
if (StringUtils.hasText(catalog)) {
simpleJdbcCall.setCatalogName(catalog);
}
for (int i = 0; i < resultJsonArray.length(); i++) {
final String resultSetKey = resultJsonArray.getJSONObject(i).getString(RESULTSET);
simpleJdbcCall = simpleJdbcCall.returningResultSet(resultSetKey, new BaseDataMapper());
}
SqlParameterSource parameters = new MapSqlParameterSource().addValues(paramMap);
LinkedHashMap<String, Object> resultList = null;
try {
log.debug("Executing Oracle procedure: {}", parameters);
resultList = (LinkedHashMap<String, Object>) simpleJdbcCall.execute(parameters);
}
So since this is a legacy project, few fields we're passed as, for example { "aPayinAmount": "100.0" } In Java 8 this did not give issues as the "100.0" was converted to int or the type Java 8 was trying to convert it to.
But when calling the simpleJdbcCall.execute(parameters); in java 21 I'm getting a type conversion error where that method tries to convert "100.0" to an integer. When I pass the value of aPayinAmount as "100", 100 or 100.0 the call to the procedure works.
This module is the backbone of the company, so all the other projects revolve around this system, which calls the stored procedures. Modifying aPayinAmount and similar fields to pass the correct value is impossible, as is modifying the field types in the Oracle procedures.
What are my option here to either modify the existing code to something more suitable for java 21 or is there any method I can try to fix this issues.
I've already tried to get the metadata of the procedures and modify the parameters before calling simpleJdbcCall.execute(parameters); but I'm not able to access the metadata as expected. This is the code I wrote for it.
private Map<String, Integer> getProcedureParameterTypes(String catalog, String schema, String procedureName) {
Map<String, Integer> paramTypes = new HashMap<>();
try (Connection conn = dataSource.getConnection()) {
DatabaseMetaData metaData = conn.getMetaData();
try (ResultSet rs = metaData.getProcedureColumns(catalog, "MAMBO", procedureName, "%")) {
while (rs.next()) {
String paramName = rs.getString("COLUMN_NAME");
int dataType = rs.getInt("DATA_TYPE");
paramTypes.put(paramName.toLowerCase(), dataType);
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return paramTypes;
}
FYI NUMBER(15,3) is the type of the PayinAmount in the table the procedure is referring to.