Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Find duplicate value

 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" )

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
done ty
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic