Results 1 to 4 of 4
Thread: Generating Dynamic Lists
- 12-01-2008, 07:20 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 12
- Rep Power
- 0
Generating Dynamic Lists
Hello, I am working on a school project. I want to generate a list of customers from a database and display it on the screen.
I have code written to get the records from the database as follows:
Assuming that code is correct, I should have a vector that contains all records in the database. Now I just want to generate a list from this vector that displays the customers first and last name. I'm not sure how to go about this, so could somebody please help??????Java Code:public static Vector getAll() { Vector customers = new Vector(); String query = "SELECT * FROM Customer "; try { ResultSet rs = stmt.executeQuery(query); boolean more = rs.next(); while(more) { String fname = rs.getString(2); String lname = rs.getString(3); String address = rs.getString(4); String city = rs.getString(5); String state = rs.getString(6); String zipcode = rs.getString(7); String phone = rs.getString(8); aCustomer = new Customer(fname, lname, address, city, state, zipcode, phone); customers.addElement(aCustomer); more = rs.next(); } rs.close(); } catch (SQLException e) { System.out.println(e); } return customers; }
Thanks
- 12-01-2008, 08:14 PM #2
Why not just use an ArrayList<Customer> that would store all your customer objects. Then just put some getter methods within your Customer class that would return the information you want.
- 12-01-2008, 09:39 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 12
- Rep Power
- 0
Ok, but once I get the information I want, how do I add it to the list? Can I just use list.add('value')?
- 12-01-2008, 10:03 PM #4
Similar Threads
-
Stacks, lists...
By little_polarbear in forum New To JavaReplies: 7Last Post: 08-02-2008, 01:59 PM -
comparision between two lists
By suprabha in forum Advanced JavaReplies: 14Last Post: 08-01-2008, 02:49 PM -
2 dimensional Lists
By gapper in forum New To JavaReplies: 4Last Post: 01-20-2008, 09:01 AM -
Tudu Lists 2.1
By JavaBean in forum Java SoftwareReplies: 0Last Post: 08-10-2007, 04:39 PM -
Tudu Lists 2.0
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-11-2007, 03:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks