Are you asking about jdbc connection or an actual SQL example?
A bit of a wild example, in mySQL, but here goes:
SELECT `appointments`.*,
`community_member`.`name`, `community_member`.`phone_number`,
`organization_community_members`.`organization_community_member_name`,
`organizations`.`organization_name`,
`appointment_state`.`appointment_state`
FROM `appointments`
LEFT JOIN `appointment_state`
ON (`appointments`.`appointment_id` = `appointment_state`.`appointment_id`
AND (`appointment_state`.`user_id` = 0
OR (`appointment_state`.`user_type` = 'volunteer'
AND `appointment_state`.`user_id` = $volunteer_id)))
LEFT JOIN `community_member`
ON (`appointments`.`is_cm_business_profile` = 0 AND `appointments`.`community_member_id` = `community_member`.`member_id`)
LEFT JOIN `organizations`
ON (`appointments`.`is_cm_business_profile` = 1 AND `appointments`.`cm_business_profile_id` = `organizations`.`organization_id`) -- CMPO
LEFT JOIN `organization_community_members`
ON (`appointments`.`is_cm_business_profile` = 1 AND `appointments`.`community_member_id` = `organization_community_members`.`organization_community_member_id`) -- CMPO Community Member
WHERE `appointments`.`end_date` >= DATE_FORMAT(NOW(), '%Y-%m-%d') -- deed end date upcoming/not overdue
AND ((`appointments`.`appointment_status_id` = 1 AND `appointments`.`v_business_profile_id` = 0 AND `appointments`.`volunteer_id` = 0) -- new (open to all)
OR (`appointments`.`appointment_status_id` = 1 AND `appointments`.`v_business_profile_id` = 0 AND `appointments`.`volunteer_id` = $volunteer_id) -- new (requested)
OR (`appointments`.`appointment_status_id` = 2 AND `appointments`.`volunteer_id` = $volunteer_id)) -- accepted (by this volunteer)