Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes Find duplicate value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Find duplicate value " Watch "Find duplicate value " New topic
Author

Find duplicate value

Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
i need to know how can i compare a string value, with the result of a SELECT

i want to add a data just if that data is not present in the database.
Ex. I add the name of a book just if that book is not already in the field BOOKSNAME of my db
Eshwar Prasad
Ranch Hand

Joined: Mar 21, 2008
Posts: 202
just query the database and populate the resultset to get the value rs.getString("BOOKSNAME")

now check the condition

if(!yourbook.equals(rs.getString("BOOKSNAME")))// here rs is ResultSet obj
{
Add book
}else{
Dont add
}
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
You could check if the select statement returns an empty resultset, if it's empty you perform the add operation, otherwise you don't

for example, you could do something like that: ( let's state that your string is "mybooktitlestring" )



Bye,
Nicola
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Alternatively, you could use the Merge statement to do it one trip to the database.

I think you are required to have an operation both if a match is found or not. But you could always set a value to itself in the matched case.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
done ty
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Find duplicate value
 
Similar Threads
JTable question
shall DataInterFace be general or specfic to FBN project?
B&S Booking and locking
I need design advice
Question about transfering data over sockets