I am using spring JDBCTemplate.
I have a scenario, where the parameters that need to be passed into my query function, are conditional/optional. For example, I have the following code:
List<RealTimeDTO> result = jdbcTemplate.query(sql, new Object[] {custId,
number, requestType, startDate, endDate}, new CCCRowMapper());
In the code, I passed in custId, number, requestType, etc.
However, requestType
is an optional parameter that may come back as null
or empty
so I don't want it to be passed into the Object[]
if it is either null
or empty
.
What can I do to handle this type of situation?
I could introduce logic where I only pass in the parameters I want into the Object[]
, however, I was wondering if there is an already built in functionality that handles this instead of me reinventing the wheel.
if
statement!! – IllegalAND requestType = ?
? – Seroka