The first one was superior in my mind for a few reasons. The story was better overall, I felt the villains and heroes were more meaningful and not throw away obstacles like in the second. Really, the villains in KOTOR2 looked far more fascinating and had somewhat intriguing back stories, but in game they really didn't amount to much. The second game had just as many glitches and buggy moments as the first one, which really should have been fixed. The second game was incomplete and that fact wasn't very well hidden, you can see it in the ending and the multiple bits of story you pick up on during the game that lead nowhere.
Don't get me wrong, I still enjoyed it and can't wait for them to finally complete the damn story in KOTOR3, I just wish they had taken a little more time to work out the kinks.