The earliest reference to the well-known verse is in Namby Pamby, a ballad by Henry Carey published in 1725, in which he himself italicized the original:

Now he sings of Jackey Horner

Sitting in the Chimney-Corner

Eating of a Christmas pye,

Putting in his thumb, Oh fie!

Putting in, Oh fie! his Thumb

Pulling out, Oh strange! a Plum.

This has been taken to suggest that the rhyme was well known by the early eighteenth century. Carey's poem is a satire on fellow writer Ambrose Philips, who had written infantile poems for the young children of his aristocratic patrons. Although several other nursery rhymes are mentioned there, the one about Little Jack Horner has been associated with acts of opportunism ever since. Just six years later it figured in another satirical work, Henry Fielding's The Grub Street Opera (1731). This had the prime minister, Robert Walpole, as its target and ends with all the characters processing off the stage 'to the music of Little Jack Horner'.

More Info: en.wikipedia.org