This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programming Diversions and the fly likes Find Exact match Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Find Exact match" Watch "Find Exact match" New topic
Author

Find Exact match

Arun Kumar
Ranch Hand

Joined: Jan 21, 2005
Posts: 129

The requirement is to receive 20 fields and match the fields against 20 field in data base and if a perfect match is found ..BINGO else need to reply to user ...no match found

On a high level its simple...but looking into the combinations 20 factorial = 2.43290201 × 10(18)

In reality there may not reach this figure but chances of the table grow int o Millions of records, is there, is there a way to find out the match with out a direct comparison
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42371
    
  64
The number of combinations doesn't come into play. At worst, you'd have to do 20 SELECT statements to find out if all elements are contained in the table. If the table gets large, you'll want to make sure that the table has an index that can be (and actually gets) used for the SELECT.


Ping & DNS - my free Android networking tools app
srinivas srinivasmeenavalli
Ranch Hand

Joined: Jul 13, 2008
Posts: 65
you'll want to make sure that the table has an index that can be (and actually gets) used for the SELECT

i agree with this.Indexing gives the best performance. You can have a dynamic query builder logic based on search criteria.



this would help you . you can prefer ibatis to create dynamic query . Ibatis suits this kind of requirements if you are coding in server side java application.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Any ORM/JDBC will have a mechanism for creating queries.

Be *very* cautious about using the code above as given, however, unless you've already made sure the variables being used to create the query are cleaned of anything that can be used to create an SQL injection attack.
Arun Kumar
Ranch Hand

Joined: Jan 21, 2005
Posts: 129

Thanks Guys

the problem here is not the select query, the table maintenance, if the table grows into say 40-50 thousand rows then the user who maintains this one will go mad

so i was hoping in suct a scenario is there any alogorithm or mathematical formula which will alow me to split the tables into multiple small tables and join then at run time to find a match
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What does the number of rows have to do with the query? We have tables with tens of millions of rows--the queries are the same.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Find Exact match