Solved

comparing strings

Posted on 2001-06-07
6
472 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SHA2 certs for IIS AND Java? 2 122
Crystal Reports Licensing Questions 4 60
Java Eclipse Loop 3 30
Coding for the first time 9 65
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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.

756 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