Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Raynard Fischer   on Jan 10 In Java Category.

  
Question Answered By: Rene Sullivan   on Jan 10

You use SQL... (see for instance: http://www.sqlcourse.com/ )

What you should do is the following:

Connection cn = .................
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery("Select pr_id,pr_name from product  WHERE
pr_id = '4'"); // note the last section here

In the WHERE clause you may put =, <, > etc. (check out the tutorial).

It is not advisable to perform searches in resultsets through java beacuse
almost always will the DBMS do it faster and more efficient. Instead you may
put your objects (here product objects) in a hashmap where the pr_id is the
key (but thats a completely different story).

However if you still decide to stay with selecting the whole table into your
resultset the only thing you can do is to parse through it until you find
the row  with the correct pr_id (either you do it or you find  someone elses
implementation). You can hopefully see that once your product catalog grows
to several hundred items your JVM will be bogged down with a lot of in
memory data and unneccesary iterations through the ResultSet.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Rowset problem Or get search suggestion and latest updates.


Tagged: