Solved

comparing strings

Posted on 2001-06-07
6
474 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 30 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

635 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