The moose likes Java in General and the fly likes JPasswordField Problem ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "JPasswordField Problem ?" Watch "JPasswordField Problem ?" New topic
Author

JPasswordField Problem ?

Jan Michael Soan
Ranch Hand

Joined: Feb 08, 2003
Posts: 36
Hello Everyone;
I've been trying so hard to compare a string in JPasswordField with the string of an sql stament like this :
String query = "SELECT Password FROM id";
I've tried several techniques but failed this techniques are :
1.) is to make another string and get the password like this :
String pass = ""+password.getPassword();
then compare it like this:
if ( query == pass ) {
SplashScreen x = new SplashScreen();
}
2.) is to change everything and instead trying it directly in an if stament like this :
if ( query == password.getPassword() ) {
SplashScreen x = new SplashScreen();
}
3.) the last is I change everything again like this one :
if ( query.equals(password.getPassword()) ) {
SplashScreen x = new SplashScreen();
}
All of this techniques failed I hope there is someone who could guide me with this problem, thanks and God Bless to everyone.
David Patterson
Ranch Hand

Joined: Jul 01, 2002
Posts: 65
There are probably a couple of problems.
1)

String pass = ""+password.getPassword();

could be simplified to

2) Your select statement probably needs a WHERE
clause. I would normally expect a SELECT
statement more like:

3) You can either build this string by
concatenating the parts, or you can use a
PreparedStatement to substitute the value
of a userid into the string dynamically.
4) To get the result, you need to setup a
Connection, and do an executeQuery on the
Statement or PreparedStatement, and get a
ResultSet. You then need to get a String
from the ResultSet's first row. THAT is what
you compare to the pass String.
5) To compare the contents of two String
variables, you should always use the
equals() method. The comparison via ==
determines if the two String fields both
refer to the same object. This is not going
to be the case when one is set from a
JPasswordField and the other is set from a
ResultSet.
David Patterson
patterd1@comcast.net
 
IntelliJ Java IDE
 
subject: JPasswordField Problem ?
 
Threads others viewed
how to get a string return from JPasswordField?
Java Swing
Comparing Password Problem in jdbc?
char to String
run-time error HELP!
Two Laptop Bag