I notice that had no sons that became king after him. Instead, his brother became king next and then after that - Zedekiah - his father's brother. So the genealogy leading to Jesus was trimmed off a bit there. Still, it was counted as being genealogy leading from David, since David was told his kingdom would never end.
Jer 22:30
30 Thus saith the LORD, Write ye this man childless, a man that shall not prosper in his days: for no man of his seed shall prosper, sitting upon the throne of David, and ruling any more in Judah.
KJV
Both Mary and Joseph were descendants of David. Women aren't usually used in Bible genealogies. But God can do anything He wants. And the important thing, it looks like - was that both the genealogies of Joseph and of Mary show that Jesus was a descendant of David, figuratively. Though of course, He was conceived by the Spirit, and not through the flesh.
Jer 22:30
30 Thus saith the LORD, Write ye this man childless, a man that shall not prosper in his days: for no man of his seed shall prosper, sitting upon the throne of David, and ruling any more in Judah.
KJV
Both Mary and Joseph were descendants of David. Women aren't usually used in Bible genealogies. But God can do anything He wants. And the important thing, it looks like - was that both the genealogies of Joseph and of Mary show that Jesus was a descendant of David, figuratively. Though of course, He was conceived by the Spirit, and not through the flesh.