NEW YORK — U.S. stocks edged higher Wednesday as energy companies climbed with the price of oil. Banks also rose, and investors sold traditionally safe stocks. A survey showed that hiring continued at a solid but uninspiring clip in July.

Stocks opened lower but gradually recovered to finish at their highest levels of the day. The price of oil jumped after the U.S. government said gasoline stockpiles shrank last week. A survey showed private U.S. business payrolls grew by 179,000 in July as retailers and shipping firms hired more workers. That suggests hiring is still healthy, but that wasn’t enough to excite investors.

“So much of this (economic) recovery could be correctly categorized as slow but steady,” said Mike Baele, senior portfolio manager with U.S. Bank’s private client reserve. “It’s all better than last year, for the most part, but it’s also all below expectations.”

The Dow Jones industrial average broke a seven-day losing streak and added 41.23 points, or 0.2 percent, to 18,355. The Standard & Poor’s 500 index gained 6.76 points, or 0.3 percent, to 2,163.79. The Nasdaq composite rose 22 points, or 0.4 percent, to 5,159.74.