The Bible is scientifically and historically accurate.
The Bible even calls the earth a "circle" that "hangs on nothing" before the world was discovered by scientists to be round sphere floating in space, hanging on nothing.A Floating Circle (The Bible Was Way Ahead Of Science On This One) James Flanders - YouTube
David was a sinful person like you and me.
David repented of his sins of adultery with Bathsheba and the murder of her husband, Uriah. He took Uriah's wife. She got pregnant. He tried unsuccessfully to get him drunk and convince him to go home (hoping he would have sex with her) when he was back from battle so he would think the baby was his. Uriah was too honorable to leave the other soldiers sleeping on the ground while he went to his comfortable home to enjoy himself, and stayed with the other soldiers. David ordered the commander of the army, Joab, to set Uriah at the front of the battle, and then withdraw from him so that he would be killed.
God knew. God sent Nathan to confront King David of his sin.
David acknowledged his sin before God.
Psalm 51A Prayer of Repentance
To the Chief Musician. A Psalm of David when Nathan the prophet went to him, after he had gone in to Bathsheba.
51 Have mercy upon me, O God,
According to Your lovingkindness;
According to the multitude of Your tender mercies,
Blot out my transgressions.
Wash me thoroughly from my iniquity,
And cleanse me from my sin.
For I acknowledge my transgressions,
And my sin is always before me.
Against You, You only, have I sinned,
And done this evil in Your sight—
That You may be found just when You speak,[a]
And blameless when You judge.
Behold, I was brought forth in iniquity,
And in sin my mother conceived me.
Behold, You desire truth in the inward parts,
And in the hidden part You will make me to know wisdom.
Purge me with hyssop, and I shall be clean;
Wash me, and I shall be whiter than snow.
Make me hear joy and gladness,
That the bones You have broken may rejoice.
Hide Your face from my sins,
And blot out all my iniquities.
Create in me a clean heart, O God,
And renew a steadfast spirit within me.
Do not cast me away from Your presence,
And do not take Your Holy Spirit from me.
Restore to me the joy of Your salvation,
And uphold me by Your generous Spirit.
Then I will teach transgressors Your ways,
And sinners shall be converted to You.
Deliver me from the guilt of bloodshed, O God,
The God of my salvation,
And my tongue shall sing aloud of Your righteousness.
O Lord, open my lips,
And my mouth shall show forth Your praise.
For You do not desire sacrifice, or else I would give it;
You do not delight in burnt offering.
The sacrifices of God are a broken spirit,
A broken and a contrite heart—
These, O God, You will not despise.
Do good in Your good pleasure to Zion;
Build the walls of Jerusalem.
Then You shall be pleased with the sacrifices of righteousness,
With burnt offering and whole burnt offering;
Then they shall offer bulls on Your altar.
The story of David's sin with Bathsheba, the murder of Uriah, and the confrontation by God's prophet Nathan is found in 2 Samuel 11-12 and I've included it here for any interested readers:
2 Samuel 11-12New King James Version (NKJV)
David, Bathsheba, and Uriah
11 It happened in the spring of the year, at the time when kings go out to battle, that David sent Joab and his servants with him, and all Israel; and they destroyed the people of Ammon and besieged Rabbah. But David remained at Jerusalem.
2 Then it happened one evening that David arose from his bed and walked on the roof of the king’s house. And from the roof he saw a woman bathing, and the woman was very beautiful to behold. 3 So David sent and inquired about the woman. And someone said, “Is this not Bathsheba, the daughter of Eliam, the wife of Uriah the Hittite?” 4 Then David sent messengers, and took her; and she came to him, and he lay with her, for she was cleansed from her impurity; and she returned to her house. 5 And the woman conceived; so she sent and told David, and said, “I am with child.”
6 Then David sent to Joab, saying, “Send me Uriah the Hittite.” And Joab sent Uriah to David. 7 When Uriah had come to him, David asked how Joab was doing, and how the people were doing, and how the war prospered. 8 And David said to Uriah, “Go down to your house and wash your feet.” So Uriah departed from the king’s house, and a gift of food from the king followed him. 9 But Uriah slept at the door of the king’s house with all the servants of his lord, and did not go down to his house. 10 So when they told David, saying, “Uriah did not go down to his house,” David said to Uriah, “Did you not come from a journey? Why did you not go down to your house?”
11 And Uriah said to David, “The ark and Israel and Judah are dwelling in tents, and my lord Joab and the servants of my lord are encamped in the open fields. Shall I then go to my house to eat and drink, and to lie with my wife? As you live, and as your soul lives, I will not do this thing.”
12 Then David said to Uriah, “Wait here today also, and tomorrow I will let you depart.” So Uriah remained in Jerusalem that day and the next. 13 Now when David called him, he ate and drank before him; and he made him drunk. And at evening he went out to lie on his bed with the servants of his lord, but he did not go down to his house.
14 In the morning it happened that David wrote a letter to Joab and sent it by the hand of Uriah. 15 And he wrote in the letter, saying, “Set Uriah in the forefront of the hottest battle, and retreat from him, that he may be struck down and die.” 16 So it was, while Joab besieged the city, that he assigned Uriah to a place where he knew there were valiant men. 17 Then the men of the city came out and fought with Joab. And some of the people of the servants of David fell; and Uriah the Hittite died also.
18 Then Joab sent and told David all the things concerning the war, 19 and charged the messenger, saying, “When you have finished telling the matters of the war to the king, 20 if it happens that the king’s wrath rises, and he says to you: ‘Why did you approach so near to the city when you fought? Did you not know that they would shoot from the wall? 21 Who struck Abimelech the son of Jerubbesheth?[a] Was it not a woman who cast a piece of a millstone on him from the wall, so that he died in Thebez? Why did you go near the wall?’—then you shall say, ‘Your servant Uriah the Hittite is dead also.’”
22 So the messenger went, and came and told David all that Joab had sent by him. 23 And the messenger said to David, “Surely the men prevailed against us and came out to us in the field; then we drove them back as far as the entrance of the gate. 24 The archers shot from the wall at your servants; and some of the king’s servants are dead, and your servant Uriah the Hittite is dead also.”
25 Then David said to the messenger, “Thus you shall say to Joab: ‘Do not let this thing displease you, for the sword devours one as well as another. Strengthen your attack against the city, and overthrow it.’ So encourage him.”
26 When the wife of Uriah heard that Uriah her husband was dead, she mourned for her husband. 27 And when her mourning was over, David sent and brought her to his house, and she became his wife and bore him a son. But the thing that David had done displeased the Lord.
Nathan’s Parable and David’s Confession
12 Then the Lord sent Nathan to David. And he came to him, and said to him: “There were two men in one city, one rich and the other poor. 2 The rich man had exceedingly many flocks and herds. 3 But the poor man had nothing, except one little ewe lamb which he had bought and nourished; and it grew up together with him and with his children. It ate of his own food and drank from his own cup and lay in his bosom; and it was like a daughter to him. 4 And a traveler came to the rich man, who refused to take from his own flock and from his own herd to prepare one for the wayfaring man who had come to him; but he took the poor man’s lamb and prepared it for the man who had come to him.”
5 So David’s anger was greatly aroused against the man, and he said to Nathan, “As the Lord lives, the man who has done this shall surely die! 6 And he shall restore fourfold for the lamb, because he did this thing and because he had no pity.”
7 Then Nathan said to David, “You are the man! Thus says the Lord God of Israel: ‘I anointed you king over Israel, and I delivered you from the hand of Saul. 8 I gave you your master’s house and your master’s wives into your keeping, and gave you the house of Israel and Judah. And if that had been too little, I also would have given you much more! 9 Why have you despised the commandment of the Lord, to do evil in His sight? You have killed Uriah the Hittite with the sword; you have taken his wife to be your wife, and have killed him with the sword of the people of Ammon. 10 Now therefore, the sword shall never depart from your house, because you have despised Me, and have taken the wife of Uriah the Hittite to be your wife.’ 11 Thus says the Lord: ‘Behold, I will raise up adversity against you from your own house; and I will take your wives before your eyes and give them to your neighbor, and he shall lie with your wives in the sight of this sun. 12 For you did it secretly, but I will do this thing before all Israel, before the sun.’”
13 So David said to Nathan, “I have sinned against the Lord.”
And Nathan said to David, “The Lord also has put away your sin; you shall not die. 14 However, because by this deed you have given great occasion to the enemies of the Lord to blaspheme, the child also who is born to you shall surely die.” 15 Then Nathan departed to his house.
The Death of David’s Son
And the Lord struck the child that Uriah’s wife bore to David, and it became ill. 16 David therefore pleaded with God for the child, and David fasted and went in and lay all night on the ground. 17 So the elders of his house arose and went to him, to raise him up from the ground. But he would not, nor did he eat food with them. 18 Then on the seventh day it came to pass that the child died. And the servants of David were afraid to tell him that the child was dead. For they said, “Indeed, while the child was alive, we spoke to him, and he would not heed our voice. How can we tell him that the child is dead? He may do some harm!”
19 When David saw that his servants were whispering, David perceived that the child was dead. Therefore David said to his servants, “Is the child dead?”
And they said, “He is dead.”
20 So David arose from the ground, washed and anointed himself, and changed his clothes; and he went into the house of the Lord and worshiped. Then he went to his own house; and when he requested, they set food before him, and he ate. 21 Then his servants said to him, “What is this that you have done? You fasted and wept for the child while he was alive, but when the child died, you arose and ate food.”
22 And he said, “While the child was alive, I fasted and wept; for I said, ‘Who can tell whether the Lord will be gracious to me, that the child may live?’ 23 But now he is dead; why should I fast? Can I bring him back again? I shall go to him, but he shall not return to me.”
Solomon Is Born
24 Then David comforted Bathsheba his wife, and went in to her and lay with her. So she bore a son, and he[c] called his name Solomon. Now the Lord loved him, 25 and He sent word by the hand of Nathan the prophet: So he[d] called his name Jedidiah,[e] because of the Lord.
Rabbah Is Captured
26 Now Joab fought against Rabbah of the people of Ammon, and took the royal city. 27 And Joab sent messengers to David, and said, “I have fought against Rabbah, and I have taken the city’s water supply. 28 Now therefore, gather the rest of the people together and encamp against the city and take it, lest I take the city and it be called after my name.” 29 So David gathered all the people together and went to Rabbah, fought against it, and took it. 30 Then he took their king’s crown from his head. Its weight was a talent of gold, with precious stones. And it was set on David’s head. Also he brought out the spoil of the city in great abundance. 31 And he brought out the people who were in it, and put them to work with saws and iron picks and iron axes, and made them cross over to the brick works. So he did to all the cities of the people of Ammon. Then David and all the people returned to Jerusalem.