I want to validate a value against values retrieved from a result set's first column. I have to do the same validation operation approximately 1000 times. So, I want to decrease the time complexity of this comparison from O(n) to constant. Is there some function through which I can put all of the values of result set's column into a hashmap without iterating?
views:
1313answers:
3
+2
A:
(I assume you're talking about a JDBC ResultSet). No, but that isn't a problem for you. It took O(n) to generate the ResultSet, so you shouldn't be worried about using O(n) more time to put them in a hashmap, or just do the validation against the whole ResultSet directly.
Keith Randall
2009-10-12 06:20:05
... not to mention that the client-side cost of iterating and building the HashMap is likely to have a much smaller 'constant of proportionality' than the cost of doing the query and transmitting the data.
Stephen C
2009-10-12 06:28:01
+1
A:
Is it possible to do the validation as part of the database query itself (in the where clause) by passing the value from your code to the query ?
Rahul
2009-10-12 06:44:53