The first historical evidence of Star of David is referred to the third century A.D. and it was found on the tombstone in Italian city of Taranto. In literature it's not mentioned until the twelfth century A.D. and it was first found only in the Eshkol ha-Kofer of the Karaite Judah Hadassah (12th century literary Hebrew piece):
Hebrew historians note that the Star of David appeared on Jewish amulets approximately in the twelfth century. It was signed on amulets on the hand with other symbols such as pentagrams, stars, the name of god in Hebrew, etc. Nevertheless it's very interesting and probably strange that pentagram, not the hexagram (the Star of David) was mostly spread in magic symbols and attributes of Jewish cult. Scientists and archeologists are not even sure if the Star of David had any similar origins in any culture of ancient Mediterranean: Hellenic or Coptic.
Some of historians assume that it might be primary used by Jewish sect of Kabbalah which adopted hexagram from Templars. Jewish sect of kabala uses David star as amulets placing it in glass spheres or using it simply as an amulet and sigh.
The spread of usage of Star of david begins in the 14th century in Jewsih communities of Europe. It's a well-known fact that the Star of david was used as decoration on Tanakh of Rabi Rabbi Yoseph bar Yehud ben Marvas from Toledo, Spain. The function of Star of David in synagogues
was to carry protective magic powers against evil. It also becomes the element of architectural ensemble in synagogues. Hexagrams are found in ornaments of cathedrals in Brandenburg and Stendhal, but it's interesting that in the ancient Jewish temple of Tell Hum it's not present and pentagram is present on its walls instead.
It's a historical fact that the Czech king of bohemia Charles IV issued the red flag with Shield of David to Juwish community of Prague in 1354. But Jews of Hungary had a red flag with pentacles. So it would be inaccurate to talk about hexagram as the symbol of Judaism and Jews back then. Moreover the majority of people in Middle Ages associated Jews with menorah rather than with another symbol of their identity.
The choice of hexagram according to modern rabbis was not sudden, as Bible scriptures have enough evidence that salvation will be associated with star. No wonder that geometric figure close to star was chosen for the role now played by the Star of David.
As it was mentioned above Torah tells that, the Messiah, will have association with star, symbolizing coming new era. And according to Old Testament Balaam had foretold the coming salvation of the people of Israel n following scriptures:
"I see him, but not now; I behold him, but not near; A star (Heb. Cochav) shall come forth from Jacob, and a scepter shall rise from Israel, and shall crush through the forehead of Moab, and tear down all the sons of Sheth. Numbers 24:17"
(from Kasdan, Barney THE STAR OF DAVID http://www.kehilatariel.org/tract002.html)
As for the meaning of the Star of David it's different for Judaists and for those who observe the cult of Kabala. Rabi describe its meaning as the symbol of unity with god: