First, you need to forget about any connection to the GUI or to comparing things.
1. On the one hand, you get data from a DB.
2. On another, totally independent hand, you extract a value from a GUI element.
3. On yet another, totally independent and unrelated hand, you compare strings.
Note that these are all totally unrelated to each other. The way you fetch from a DB is the same regardless of whether your app has a GUI and regardless of what you're going to do with the String, such as compare it. The way you compare Strings is completely independent of where the Strings come from.
So, don't ask "How do I compare a String from the DB with a String in the GUI?" Instead, narrow your question down and focus on which of #1, #2, or #3 you're currently having trouble with. Since you seem to be asking about interacting with a DB, I will point you toward googling for JDBC tutorial.