According to Wikipedia:
Five presidents had never been elected to public office before becoming president: Zachary Taylor, Ulysses S. Grant, Herbert Hoover, Dwight D. Eisenhower, and Donald Trump. Most of these had, however, been appointed to several prominent offices. Hoover's contributions toward the Treaty of Versailles preceded his appointment as United States Secretary of Commerce. Taylor, Grant, and Eisenhower led U.S. forces to victory in the Mexican–American War, American Civil War, and World War II, respectively – each occupying the highest-ranking command post of their time. Trump is the group's sole exception, having never held any public office nor any military position.