Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

comparing strings

Posted on 2001-06-07
6
Medium Priority
?
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

664 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