It was not a reference to a jelly doughnut, as David Emery in About.com explains in reply to a question:
"I have heard and read from several different sources the story that John F. Kennedy made a major German language blunder in his famous 'Ich bin ein Berliner' speech in Berlin, Germany. The story goes that he should have said 'Ich bin Berliner' ('I am a citizen of Berlin'), and that 'Ich bin ein Berliner' really means 'I am a jelly doughnut.' (A Berliner is in fact a type of jelly doughnut made in Berlin.)
"Several years ago when I visited Germany, I found myself having drinks with a German journalist who struck me as fairly intelligent, so I asked her the question. She said that it is certainly not true. President Kennedy said the phrase absolutely correctly, although possibly with a thick American accent... She said that if President Kennedy had said, 'Ich bin Berliner,' he would have sounded silly because with his heavy accent he couldn't possibly have come from Berlin. But by saying 'Ich bin ein Berliner,' he actually said 'I am one with the people of Berlin.' "
"Your friend, the journalist, was on the mark. This is truly The Gaffe That Never Was, despite reports to the contrary in venues as prestigious as the New York Times and Newsweek magazine. Experts say Kennedy's German grammar was flawless when he uttered those words near the Berlin Wall on June 26, 1963. The phrase had been translated for him by a professional interpreter.
"It is true that the word "Berliner" in German denotes a particular kind of jelly-filled pastry as well as a citizen of Berlin. But look at it this way: If I were to tell a group of Americans that my editor is a New Yorker, would any of them really think I've confused him with a well known weekly magazine?
"...while the proper way for a Berlin native to say 'I am a Berliner' is 'Ich bin Berliner,' the proper way for a non-native to make the same statement metaphorically is precisely what Kennedy said: 'Ich bin ein Berliner.' In spite of the fact that it's also the correct way to say 'I am a jelly doughnut,' no adult German speaker could possibly have misunderstood Kennedy's meaning in context."