The Dow and S&P 500 gained on Wednesday on economic optimism spurred by a jump in bank shares as investors bet that capital shortfalls will be manageable, plus reassuring labor market data and Walt Disney's better-than-expected profit.

Energy shares also gave the broad market a lift as the price of oil climbed above $56 a barrel at midday on the private-sector jobs data and just a slight increase in crude inventories. Chevron gained 2.7 percent to $67.50.

The Nasdaq was held under water as investors took profits on Apple and other bellwether names. Apple was off 1.3 percent at $130.96. But Research In Motion gave one of the biggest lifts to the Nasdaq after JP Morgan upgraded the BlackBerry maker's stock to neutral from underweight.

RIM was up 2 percent at $76.88.

Shares of major banks advanced, pushing the KBW Bank index <.BKX> up 7.5 percent. Regulators are ordering the largest U.S. banks to get tens of billions of dollars of capital to cushion themselves in case of a deep economic downturn.

The results of government stress tests on 19 major U.S. financial institutions are set to be unveiled on Thursday. Among gainers, Bank of America shot up 13.8 percent to $12.34 and Citigroup gained 6.7 percent to $3.53.

The market likes the certainty of putting numbers on the worst-case scenarios of how much capital these banks need, said Chris Armbruster, an analyst at Al Frank Asset Management, in Laguna Beach, California.

The Dow Jones industrial average <.DJI> rose 28.59 points, or 0.34 percent, to 8,439.24. The Standard & Poor's 500 Index <.SPX> gained 4.99 points, or 0.55 percent, to 908.79. The Nasdaq Composite Index <.IXIC> was off 13.02 points, or 0.74 percent, to 1,741.10.

In economic news, ADP data showed private-sector job losses slowed in April, coming in below expectations and providing further reason for optimism that the U.S. economy has seen the worst before the government's release of the monthly non-farm payrolls report on Friday.

Walt Disney Co gave the Dow its biggest boost, jumping 11.2 percent to $25.76 after the No. 1 U.S. entertainment company posted a quarterly profit above Wall Street's forecasts after Tuesday's closing bell.

Disney's results gave more support to views that the economy may be stabilizing and consumers may be regaining some confidence.

Since hitting a bear market closing low in early March, the S&P 500 has surged 34.4 percent, driven by optimism about the financial system's condition and hopes the recession may be waning.

(Additional reporting by Jonathan Stempel; Editing by Jan Paschal)