Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-01-2008, 08:20 PM
Member
 
Join Date: Nov 2008
Posts: 12
Rep Power: 0
jmorris is on a distinguished road
Default 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:

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;
	}
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??????

Thanks
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-01-2008, 09:14 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 585
Rep Power: 2
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-01-2008, 10:39 PM
Member
 
Join Date: Nov 2008
Posts: 12
Rep Power: 0
jmorris is on a distinguished road
Default
Ok, but once I get the information I want, how do I add it to the list? Can I just use list.add('value')?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-01-2008, 11:03 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 585
Rep Power: 2
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
Default
You could just create another ArrayList<String> or just a String[]. For the first way it would be list.add(firstName+", "+lastName) and for String[] I believe its the same command.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stacks, lists... little_polarbear New To Java 7 08-02-2008 02:59 PM
comparision between two lists suprabha Advanced Java 14 08-01-2008 03:49 PM
2 dimensional Lists gapper New To Java 4 01-20-2008 10:01 AM
Tudu Lists 2.1 JavaBean Java Announcements 0 08-10-2007 05:39 PM
Tudu Lists 2.0 JavaBean Java Announcements 0 07-11-2007 04:32 PM


All times are GMT +2. The time now is 07:14 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org