David recognized that God had been good and gracious to him by entering into the covenant with him. David didn't deserve to have a descendent on the throne forever. He didn't earn that right. No one does. But God graciously made that promise to him, and he was thankful.