Hello all, i wonder if some kind soul could point me in the right direction.
I'm sure the solution is VERY straightforward but for some reason i just
can't see it.. just call me Mr. Thicky. Anyway... here it is....
I have a main method that passes a parameter to another method used to
perform an SQL query. What i want to do is to return the result (ResultSet)
as an enumeration for the main method to display. Here's the partial code...
// The main method passes 'Meat' to the getCategoryOfStk
// method
public static void main(String[] args){
try{..........
.......
StkCollection stkColl= new StkCollection
System.out.println("Testing getCategoryOfStk");
Enumeration enum = stkColl.getCategoryOfStk("Meat");
while(enum.hasMoreElements()){
System.out .println((CD)enum.nextElement());
}............
// The constructor of the StkCollection class creates the link to the
database. The getCategoryOfStk method called is shown below:
public Enumeration getCategoryOfStk(String category)throws SQLException{
String reqdCategory=category;
Enumeration e; // used to return details?
try
{
Statement state = cn.createStatement();
//perform DB query....
String getCategoryQuery =
"Select * from Stock where Category='"+reqdCategory+"'";
ResultSet rs = state.executeQuery(getCategoryQuery);
// OK all is fine to this point we have the results in ResultSet rs. My
problem is how to return the results as an enumeration type back to the main
method for display. Do i need to Cast the ResultSet rs to an Enumeration
type? Or am i totally barking up the wrong tree and i need to implement the
Enumeration interface?
}catch(Exception ex)
{System.out.println("Problem executing query"+ex);}
return e; // somehow return the enumeration
}
Any help would be gratefully received and will stop me banging my head on
the desk.
Kind Regards,
Andy
On Wed, 28 Dec 2005 20:24:05 GMT, "Andy Bailey"
<andy.bailey1@ntlworld.com> wrote, quoted or indirectly quoted someone
who said :
> Do i need to Cast the ResultSet rs to an Enumeration
>type? Or am i totally barking up the wrong tree and i need to implement the
>Enumeration interface?
You need to return an object that implements the Enumeration (or
Iterator to be modern) Interface.
This class his burned into it the information needed to get at each
row, i.e. you pass it the resultset to its constructor. It can be an
anonymous class. Have a look at source code in src.zip that returns
Enumerations or Iterators to see how they do it.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.