Lets say I have this:
String sql = "DELETE FROM "+ TABLE_NAME +" WHERE id=?";
try {
int ra = jdbcTemplate.update(connection -> {
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setLong(1, id);
stmt.executeUpdate();
return stmt;
});
if (ra == 0)
throw new SQLException(SQL_ERROR);
} catch (SQLException e){
LOGGER.error(SQL_ERROR);
throw new DataAccessLayerException("Entity could not be deleted due to SQL Exception");
}
I am deleting a entity from table with key(id). Now I want to be able to report INTERNAL_SERVER_ERROR
to client without causing a RuntimeException
.
However, I can't reproduce SQLException
. If I for example delete a letter in my sql statement I only get a Syntax error that is thrown as Runtime error and it seems like I am not catching it.
Help me understand what is exactly meant here with SQLException and how do I reproduce it and report this to client without causing RuntimeException?