springframework.dao.EmptyResultDataAccessException
while trying to select the data from the sql server database, here is the code I have written. Can anybody suggest how to select data from database using query interface?
public int getRedempRequestId(RedemptionResponseBean redemptionResponse)
throws ParseException {
final Timestamp redempIdFromCsv = getRedeemDate(redemptionResponse);
int participantId = redemptionResponse.getOcpEventMemberId();
System.out.println(redempIdFromCsv);
System.out.println(participantId);
int res = jdbcTemplate.queryForInt("SELECT RR.REDEMPTION_REQUEST_ID "
+ "FROM dbo.REDEMPTION_REQUEST RR WITH (NOLOCK)"
+ "WHERE RR.SENT_DATE = ? AND "
+ "RR.OEDEF_OCP_EVENT_MEMBER_ID = ? ", new Object[] {
redempIdFromCsv, participantId });
System.out.println(res+"-----------");
return res;
}
could anybody tell me what's the problem here?
If you expect no data to be returned, you shouldn't use jdbcTemplate.queryForInt(...)
, since that method expects the query it will execute will return an integer value. Basically, that is what the EmptyResultDataAccessException
is telling you; its Javadoc says:
Data access exception thrown when a result was expected to have at least one row (or element) but zero rows (or elements) were actually returned.
Instead, you should use one of the query(...)
methods from JdbcTemplate
, which allow for zero rows to be returned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With