Stocks reversed early losses on Wednesday, gaining as resource shares were boosted by increases in commodity prices and a further-weakened U.S. dollar.

The Dow Jones industrial average rose 31.43 points, or 0.31 percent, to 10,317.40. The Standard & Poor's 500 Index put on 1.81 points, or 0.17 percent, to 1,093.75. The Nasdaq Composite Index added 1.29 points, or 0.06 percent, at 2,174.28.