Confidence in prayer would be the last thing I'd expect from this Psalm, at least from the very beginning of it. It strangely moves from questioning insecurity to strong confidence with no quickly discernible path between the two extremes. Maybe that is the way faith works sometimes.
David starts out begging God not to punish him, as if in fear that he has sinned and incurred God's justice (6:1). He then is emotionally spent (6:2), and is so troubled in his soul as to be confused by God's seeming inactivity (6:3). He feels like he might die and begs God to spare him (6:4-5). He is so full of grief that he cannot sleep (6:6-7).
And then David turns to confront evil people who are against God, informing them that as emotionally spent as he is, he knows God has heard his prayers (6:8). And that is where the confidence enters the scene. It is somehow found in camparison to those without God. David would rather struggle with difficult circumstances that throw him upon God, then to miss God altogether in unbelief. And that seems to be the source of his confidence. He believes God answers prayer because he believes God.