File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Vector filtering VS. MySQL filtering Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vector filtering VS. MySQL filtering" Watch "Vector filtering VS. MySQL filtering" New topic
Author

Vector filtering VS. MySQL filtering

SuryaP Prakash
Greenhorn

Joined: Jan 08, 2004
Posts: 4
Hello All,
I am slightly confused on a small problem and was wondering if I could get your thoughts on it -
I have a Vector of objects from which I need specific data - object where a=1 and b=2, etc. Then based on the results of one set of specifics (a=1, b=2), I need to extract other data from this vector. Basically, a set of functions related to this task (countAll(), countUnique(), totalAll(), etc).
My other option (and easier one) is to use the for loop statements alongwith MySQL logic queries. The only problem is that I know that db connectivity is expensive in terms of time and resources.
My question is what is the correct way of doing this?
Do let me know. Thanks in advance,
S
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The only problem is that I know that db connectivity is expensive in terms of time and resources.
The time taken to create a database connection is almost negated if you use a Connection Pool, and you'll have to use the databases resources if you want to connect at all, so I wouldn't worry about that either.
In some ways you may find that the database is much better at filtering the values than your Java code, so you could easily push the logic to the database. The other advantage to doing it on the database is that you don't need to transmit the results from the database to the Java code before filtering, you are always sending the smaller set of data.
One down-side to pushing it to the database is to be wary of pushing your business logic onto the database. You can create situations where your application becomes database dependent because of non-standard SQL, or business logic could be spread across two tiers.
Dave
SuryaP Prakash
Greenhorn

Joined: Jan 08, 2004
Posts: 4
David,
Thanks for your reply. Appreciate it - it was the most helpful reply I received from over 3 message boards.
Thanks again.
Surya
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

It's not me, it's the JavaRanch. We're always happy to help
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch SuryaP!
Don't let [url=http://www.javaranch.com/contact.jsp#DavidO'Meara]David's[/url] down under charm fool you. He's a wealth of great information.
I'm moving this thread to the JDBC forum...
[ January 09, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Vector filtering VS. MySQL filtering