Stocks rallied on Wednesday as shares at 12-year lows lured investors to break a five-day sell-off and a jump in oil and other commodities boosted energy and natural resource companies.

Investor optimism was also bolstered by news that China will increase spending in areas such as infrastructure and manufacturing under a second stimulus package. Data suggested that China's economy may also be on the brink of a recovery.

Dow component Caterpillar Inc , a big exporter to China and a major seller of equipment to the mining industry, jumped 14 percent to $25.61. Mining equipment maker Joy Global Inc posted a higher-than-expected quarterly profit and backed its 2009 outlook, sending its stock up 11.7 percent at $17.70.

The market has taken a real beating this year, so it's very oversold and therefore responsive to any kind of good news it can get, said Bruce Bittles, chief investment strategist at Robert W. Baird & Co in Nashville.

The market has to prove that it's finally built in the worst-case scenario for the economy.

The Dow Jones industrial average <.DJI> rose 160.25 points, or 2.38 percent, to 6,886.27. The Standard & Poor's 500 Index <.SPX> added 16.13 points, or 2.32 percent, to 712.46. The Nasdaq Composite Index <.IXIC> gained 33.07 points, or 2.50 percent, to 1,354.08.

For the year to date, however, the Dow and S&P are both down more than 21 percent after recent declines that have seen the indexes fall through key levels.

General Electric pushed against the current, falling 4.3 percent to $6.71, as investors worried about the health of its financial arm and banks in general.

Financials <.GSPF> were the only group out of the S&P's 10 sectors to fall, losing 2 percent, amid ongoing worries over the fate of the struggling banks. JPMorgan Chase was the Dow's biggest drag, down 7.4 percent at $19.45, and Citigroup fell 2.7 percent to $1.19.

Oil prices in New York rose 8.7 percent to $45.28 a barrel, while the Reuters-Jefferies CRB <.CRB> index of 19 commodity futures rose 3 percent in its biggest one-day percentage jump since late January.

Shares of Chevron rose 3.2 percent to $59.56, while miner Freeport-McMoRan Copper & Gold Inc surged 13.5 percent to $32.24.

On Nasdaq, Apple was the top boost with a gain of 4.1 percent to $92.00, while Intel Corp rose 4.6 percent to $12.85.

The rise in big-cap technology stocks also supported gains in chip-makers' shares, pushing the semiconductor index <.SOXX> nearly 5 percent and Broadcom Corp up 5.3 percent t $16.63.

(Editing by James Dalgleish)