David sinned with Bathsheba but her second son by David became king and built the temple.