Both took place during similar times in European history, relatively speaking. Is there any particular reason for this? Did one's occurrence influence the other's?
In short: the establishments of these countries all had their foundations in the rise of nationalism and the idea of a nation-state.
During that period of time, nationalism gained a lot of support in Europe. Both modern-day Italy and modern-day Germany (which had a different border back then) were in fact one people divided over several kingdoms and states. The idea of nationalism was to have a nation-state for one people. It was the same period that all countries started developing a feeling of national unity: anthems, flags, a common history...