class ListenerRepo {

    public Listener insert(Listener listener, Connection connection) throws DataAccessException {
        try (
                PreparedStatement stmt = connection
                        .prepareStatement(INSERT_LISTENER_QUERY, Statement.RETURN_GENERATED_KEYS)
        ) {
            if (listener.getId() == 0l) {
                stmt.setObject(1, null);
            } else {
                stmt.setObject(1, listener.getId());
            }
            stmt.setObject(2, listener.getTableName());
            stmt.setObject(3, listener.getWaitTimeout());
            stmt.executeUpdate();

            ResultSet rs = stmt.getGeneratedKeys();

            rs.next();
            long genId = rs.getLong("GENERATED_KEY");
            return findById(genId, connection);

        } catch (SQLException e) {
            throw new DataAccessException("Couldn't insert listener", e);
        }
    }

}