Generic method to retrieve from database