Expose for the brightest things in the scene. You can often pull details out of the shadows, but once something goes pure white then there's nothing you can do. In this case the exposure settings for your first image are preferable.
Canon has a mode called Highlight Tone Priority which is designed for situations like this, which will underexpose the image to protect the highlights and then boost the shadows and midtones to obtain a less dark looking picture. I think Nikon's active d-lighting is similar.
Alternatively if you shoot raw you can get the same effect (but with more control) when you do your raw conversion (provided you haven't blown the highlights).
Finally you can combine exposures as Itai suggests using a technique called HDR. This requires extra preparation such as using a tripod, shooting multiple exposures (which creates difficulties if you have movement), and a lot more fiddling in post production to get good looking results.
In summary I would suggest shooting single raw images, exposing for the highlights and boosting the shadows during raw conversion.