Newbie help! Returning an enumeration
- From: "Andy Bailey" <andy.bailey1@xxxxxxxxxxxx>
- Date: Wed, 28 Dec 2005 20:17:04 GMT
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
.
- Follow-Ups:
- Re: Newbie help! Returning an enumeration
- From: hiwa
- Re: Newbie help! Returning an enumeration
- Prev by Date: Deleting a Row in a JTable
- Next by Date: JTable too Wide
- Previous by thread: Deleting a Row in a JTable
- Next by thread: Re: Newbie help! Returning an enumeration
- Index(es):
Relevant Pages
|