This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Find duplicate value

 
Antony Amicone
Ranch Hand
Posts: 125
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
done ty
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic