Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector filtering VS. MySQL filtering

 
SuryaP Prakash
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not me, it's the JavaRanch. We're always happy to help
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch SuryaP!
Don't let [url=http://www.javaranch.com/contact.jsp#DavidO%27Meara]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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic