Did Jesus have the ability to sin? The problem hidden in that question is that if Jesus did have the ability to sin, does that mean he had original sin and participated in a fallen nature? If that were the case, he wouldn't even be qualified to save himself, let alone us. If he did not have the ability to sin, was his temptation (so central to God's giving him the crown of glory for his obedience) just a charade—was he really not subjected to real temptation?
The New Testament tells us that Jesus was like us at every point save one: He was without sin. It tells us that Jesus became incarnate and took upon himself human nature. It also tells us that he is the second Adam. Generally, classical Christology teaches that when Jesus was incarnate and became the new Adam, he came born with the same nature that Adam had before the Fall. Adam didn't have original sin when he was created. So Jesus did not have original sin. So we would ask the same question: Was Adam capable of sinning? Yes, he was. Christ, the second Adam, was also capable of sinning in the sense that he had all of the faculties and all of the equipment necessary to sin if that's what he chose to do.
Could Jesus have sinned if he had wanted to? Absolutely. Of course, he didn't want to. So if you ask it a different way, could Jesus sin if he didn't want to? No, he couldn't sin if he didn't want to any more than God could sin because God doesn't want to sin. Wanting to sin is a prerequisite for sinning.
But then we have to push it one step further: Could Jesus have wanted to sin? Theologians are divided on this point. I would say yes, I think he could have. I think that's part of being made after the likeness of Adam. When we're in heaven and are totally glorified, then we will no longer have the power and ability to sin. That's what we look forward to; that's what Jesus earned for himself and for us through his perfect obedience. Christ's perfect obedience was not a charade. He actually was victorious over every conceivable temptation that was thrown his way.