I'm afraid I don't understand your question. These two verses say the same thing. In fact, the verse in John 18:9 is a direct reference to the message also contained in John 17:12.
Here are the verses:
John 17:12 (Christ is speaking to the Father)
"While I was with them, I was keeping them in Your name which You have given Me; and I guarded them and not one of them perished but the son of perdition, so that the Scripture would be fulfilled."
Jesus answered, "I told you that I am He; so if you seek Me, let these go their way," to fulfill the word which He spoke, "Of those whom You have given Me I lost not one."
Since the one fulfills the other and the message in both are the same, I am not sure what aspect or aspects of these two verses appear contradictory to you...?
I am happy to do my best to address any question you may have about Christianity, as long as the question is clear and coherent. Please, if asking questions like this in the future, make sure to state EXACTLY WHAT the contradiction is in your mind, because it isn't apparent to me.
God bless you in your pursuit of truth.