Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

ADO's RecordSet.Find or RecordSet.Filter in JDBC

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any method like ADO's RecordSet.Find or RecordSet.Filter in JDBC ?

I'm retriving full table. I want to check if a particular ID exists or not.

If you convert VB code to java syntax, it should look something like this:


[ August 13, 2007: Message edited by: Piash Chaudhuri ]
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe I am misunderstanding your question, but why can't you just do SELECT id FROM some_table WHERE id=some_id. If you get a result back then you know it exists. If the result set is empty, then it doesn't.
 
Piash Chaudhuri
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The names array can contain 10000s of elements and I need to check each of them inside a loop.

If I use WHERE clause then I'll need to reopen the resultset in every iteration. I'm not 100% sure, but my guess is, WHERE will be slower than find/filter method (which opens the recordset only once).
[ August 14, 2007: Message edited by: Piash Chaudhuri ]
 
Chad Clites
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know of any JDBC function that does what you describe, but I have never looked for one either. I do either one of two things (and I assume that any filtering function is doing the same thing). The first thing common to both methods is that I need to build a resultSet that contains the values that I want to check. Then I dump them into a collection of some sort. Personally, I use a hashSet. I can check entries one at a time without having to re-query the database. If not, I am notified of the absent entry and can correct it on the spot. This works ,for example, if people are registering for a seminar, and I want to see if they are on the database.

The other method would be to put all the values I want to check into a list, and as I am iterating through the resultSet, see if the term from the resultSet is contained within my list. This is useful if I already have a list of values and I want to validate all of them. I can do hundreds of thousands of validations in very little time.

Either way, it can be accomplished with just a few lines of code.
[ August 14, 2007: Message edited by: Chad Clites ]
 
Piash Chaudhuri
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for sharing ideas !
I endeded up using your first suggesation. WHERE inside a loop.

BTW, I was wrong. ADO's .find and .filter are A LOT slower than pure SQL.
http://articles.techrepublic.com.com/5100-22-1045830.html

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic