TLTEO
asked on
comparing strings
I am using JDBC. First I am getting 2 data from a field
ie Select sernum,cardnum From mydb where this1='x' AND this2='y'
I like to compare if sernum='123456XYZ'
cardnum='SRZ25364'
I use collators, but find that they are not very good.
Cud someone recommend me a way to compare strings and validate so as to authenticate a person
ie Select sernum,cardnum From mydb where this1='x' AND this2='y'
I like to compare if sernum='123456XYZ'
cardnum='SRZ25364'
I use collators, but find that they are not very good.
Cud someone recommend me a way to compare strings and validate so as to authenticate a person
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
first check that the strings r retreiving or not ! If the strings r coming n then check the strings as a resultset usig equals method !
The synstax is
if(str.equals(str2))
this means that Is string str is equal str2 or not by values not by the address ?
I think this will solve ur problem !
Thanx
Rohit
The synstax is
if(str.equals(str2))
this means that Is string str is equal str2 or not by values not by the address ?
I think this will solve ur problem !
Thanx
Rohit
Hello tlteo,
I think you are doing this
String sernum = "123456XYZ";
String cardnum = "SRZ25364";
String sql = "Select sernum, cardnum from mydb where sernum = " + sernum + " and cardnum = " + cardnum;
the above line won't help you because missing of single quote in the query.
do like this.
String sql = "Select sernum, cardnum from mydb where sernum = '" + sernum + "' and cardnum = '" + cardnum + "'";
Say Connection is c;
Statement s = c.createStatement(sql);
ResultSet rs = s.executeQuery(sql);
I think it will help you
All the best
Cheers,
Muru
I think you are doing this
String sernum = "123456XYZ";
String cardnum = "SRZ25364";
String sql = "Select sernum, cardnum from mydb where sernum = " + sernum + " and cardnum = " + cardnum;
the above line won't help you because missing of single quote in the query.
do like this.
String sql = "Select sernum, cardnum from mydb where sernum = '" + sernum + "' and cardnum = '" + cardnum + "'";
Say Connection is c;
Statement s = c.createStatement(sql);
ResultSet rs = s.executeQuery(sql);
I think it will help you
All the best
Cheers,
Muru
lowercase (or uppercase) the strings before you compare them
ASKER
I check whether rs.next(), else return null.
this actually solve the problem. Thanks vm
this actually solve the problem. Thanks vm
then check if the query returned empty results
seve