The pattern of David's thoughts in this section is very similar to that expressed in verses 1-5. It is a second cycle of the same lament and confidence expressed there.
22:6-8 By comparing himself to a worm David was expressing his feelings of worthlessness, vulnerability, and contempt in the eyes of his enemies. These foes were insulting him, despising him, and mocking his faith in God because the Lord was not rescuing him (cf. Matt. 27:39, 44). The Lord Jesus' enemies spoke these very words as He hung on the cross (Matt. 27:42-43).
22:9-10 Nevertheless David drew strength from his remembering that God had sustained him all his life, even from his birth. When David was only a small boy he had learned to trust in the Lord who had sustained him to the present day.