I didn't count them because they did have brief political careers between the end of their army service and the beginning of their presidencies.
Jackson was active in politics long before his brief military command: he was a US Representative and Senator in 1796-1798. He returned to the Senate in 1823, serving until 1825.
Harrison was a soldier from 1791 to 1798 (as a junior officer), and again in 1811 to 1814 (as an army commander).
His political career was far more extensive. In 1798 he was elected Congressional Delegate from the Northwest Territory. In 1801 he was appointed Governor of Indiana Territory, serving until 1812. After resigning from the army in 1814, he moved to Ohio, and was elected US Representative in 1816. In 1819 he was elected to the Ohio state senate; in 1820 he ran for governor; in 1822 he ran for US Representative; and in 1824 was elected US Senator, serving until 1828, when he was appointed US Minister to Colombia (where he stayed only three months).
From 1829 to 1836, he was a private citizen. In 1836 he was appointed Clerk of Courts for Hamilton County - because he was nearly broke and needed a job. At the same time, he retained a national reputation, and was one of three regional candidates nominated for President by the new Whig Party in 1836. He carried nine states.
So by 1840, he had been active in politics for about 25 years, which is hardly brief.