Two Laptop Bag*
The moose likes JDBC and the fly likes Query database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Query database" Watch "Query database" New topic
Author

Query database

Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
I need to get some information from a table and use it to populate a vector. I have examples of how to query the table but I don't have any examples on what to do with the info once I get it. Like once I get a stockname from the table how do I refer to that in the program. Am I making myself clear?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Take a look at a recent Intermediate Forum thread on this topic.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
I have a statement in my program like:

What this returns is the values in the first field of my table. So I would think that rs.getString(2) would return the values in the second field of my table. But no it throws an exception instead. So how do I go about getting the second field?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
You could do it in the following manner.
Consider a table named student with three columns - idNo, fName, and lName - that are all varchars. The following code would print to the console a listing of everybody in the table.Does that help to give you an idea?
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
That is definitely helpful. I can understand doing it that way much better than the way I was doing it. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query database
 
Similar Threads
Relationship between tables in DAO pattern
Check for duplicates in database before insert
oracle date between
SQL help!
how to get the inserted record by using resultset in java?