Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

comparing strings

Posted on 2001-06-07
6
Medium Priority
?
477 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
ID: 6163003
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 120 total points
ID: 6163332
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
ID: 6163355
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Expert Comment

by:mmuruganandam
ID: 6167908
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
ID: 6178502
lowercase (or uppercase) the strings before you compare them
0
 

Author Comment

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

972 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