Everyone breaks. Under the UCMJ, it is not considered a crime or fault if it is under ‘extreme duress’. I think five years of torture would qualify as extreme duress. Even then, McCain just gave his ship name, something they most likely already had considering he was high profile. Nothing he gave jeopardized the lives of his fellow soldiers.
Reading his book and other’s accounts, most of the time, he was able to evade by giving smarta** answers such as the names of a football team’s line up.
Heck, the NVA coulda got the carrier name from the American newspapers. They could have examined the wreckage of McCain's A4 Skyhawk & probably found the panel with the ship's name stenciled on it (unless they don't do that on combat deployments). They might have had his navigation boards, too.
Another poster suggested that McCain's detractors couldn't hold out a day, week, or month under that treatment. Perhaps. But the really difficult part is NOT knowing the hour of your release. You have no future to look forward to.