Solved

comparing strings

Posted on 2001-06-07
6
466 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:TLTEO
6 Comments
 
LVL 3

Expert Comment

by:SEve
Comment Utility
Select sernum,cardnum From mydb where this1='x' AND this2='y' AND sernum='123456XYZ' AND cardnum='SRZ25364'

then check if the query returned empty results

seve
0
 

Accepted Solution

by:
rohitgautam earned 30 total points
Comment Utility
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
0
 

Expert Comment

by:rohitgautam
Comment Utility
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
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 9

Expert Comment

by:mmuruganandam
Comment Utility
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
0
 
LVL 1

Expert Comment

by:jimsims
Comment Utility
lowercase (or uppercase) the strings before you compare them
0
 

Author Comment

by:TLTEO
Comment Utility
I check whether rs.next(),  else return null.
this actually solve the problem.  Thanks vm
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now