Congratulate yourself on having good intuition the first time around. You knew that he was unavailable so you ended the relationship. Good job!
Now you need to look at why you are attracted to unavailable men. Was your father or mother emotionally distant in any way? We tend to attract (and be attracted) to people who have certain qualities that our parents have, even if we don't like those qualities. When we are willing to take a look at that, we can heal those pattern and attract partners who are emotionally available and commit to us.