File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Am I doing this correctly? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Am I doing this correctly?" Watch "Am I doing this correctly?" New topic

Am I doing this correctly?

Al Wells
Ranch Hand

Joined: Apr 18, 2005
Posts: 87
I am totally new to Java. I am trying to get a query to execute which will return to a combo box in another class. I am confused about the Vector functions and how to make them work. The book that I am working from is not clear to me.

Again, all I want to do is to have the DB look up all facilities. Then I want to create the object that does that (FacilityList) and display the values in a combo box in the class where it needs to be displayed (not included in the code below). I am sure that something is way off. I don't get this to compile yet because of the "DownRow" method. But, I am not sure that any of it is right anyway. Thanks for the help.

Here is the code:

Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
OK, there are a few problems here.

First thing I would say is try to use the normal naming conventions for variables. i.e. start with lower case.

The second main problem I see is with your DownRow method. You try currentRow.addElement(DisplayResults). DisplayResults is a ResultSet. I'm pretty sure you don't want to add the ResultSet to the vector, rather you want to add some information from the database rows in the result set. The result set will contain entries for each row returned by your query. You have to access this information using methods like getInt("columnName") to retrieve data for a column, and next() to advance to the next row returned by the database.

Rather than re-write your problem. I've written a simple example, which hopefully you can work from:

Al Wells
Ranch Hand

Joined: Apr 18, 2005
Posts: 87
Thank you Horatio.

That solved a whole bunch of problems and helped me see the light all at the same time. Thanks so much.

I agree. Here's the link:
subject: Am I doing this correctly?
jQuery in Action, 3rd edition