Search.java:

package com.monkeygarage.carclubhub.clubinfo;
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.util.logging.Logger;
import com.monkeygarage.DBConnect;
import java.util.logging.Level;
import java.util.*;

public class Search 

{
	private List<SearchResults> list = new ArrayList<SearchResults>(); 
	DBConnect db = new DBConnect(); 
		public Iterator getResult() {
		Result();
		return list.iterator();
		}
	
	
	private void Result()
	{
		try {
			ResultSet rs = db.getResult("SELECT club.clubId, " +
					"club.clubName, club.clubDescrip, " +
					"clubaddress.zipcode, state.stateName FROM club, " +
					"clubaddress, state WHERE clubaddress.stateId=38 " +
					"AND clubaddress.clubId = club.clubId AND " +
					"clubaddress.stateId = state.stateId");
			
			list = new ArrayList();
			
			while(rs.next())
					{
				list.add(new SearchResults(rs.getLong(1), rs.getString(2),
						rs.getString(3),rs.getLong(4),rs.getString(5)));
					}
			}		
		catch (SQLException ex) {LOGGER.log(Level.SEVERE, "Error", ex);}
					
	
			
			finally 
			{ db.disconnect(); } 
				
	
		}
	private static final Logger LOGGER = Logger.getLogger(Search.class.getName());
	public static void main(String[] args) {
		Search list = new Search();
		Iterator it = list.getResult();
		
	
		}

}

SearchResults.java:

package com.monkeygarage.carclubhub.clubinfo;

public class SearchResults {
	private Long clubId;
	private String clubName;
	private String clubDescrip;
	private Long zipcode;
	private String stateName;
	
	SearchResults(Long clubId, String clubName,
	String clubDescrip,
	Long zipcode,
	String stateName)
	{
		this.clubId=clubId;
		this.clubName=clubName;
		this.clubDescrip=clubDescrip;
		this.zipcode=zipcode;
		this.stateName=stateName;
	}
	
	public Long getClubId(){
		return clubId;
	}
	
	public String getClubName(){
		return clubName;
	}
	
	public String getClubDescrip(){
		return clubDescrip;
	}
	
	public Long getZipcode(){
		return zipcode;
	}
	
	public String getStateName(){
		return stateName;
		}
	
	public Long toLong() { return this.clubId; }
	
	public String toString() { return this.clubName; }
	
	public String toString() { return this.clubDescrip; }
	
	public Long toLong() { return this.zipcode; }
	
	public String toString() { return this.stateName; }
}

obviously I'm getting errors from the last 5 lines in SearchResults.

I'm trying to get

public static void main(String[] args) {
		Search list = new Search();
		Iterator it = list.getResult();
		
	
		}

to actually output the results, but I'm a little confused as to how, and I also wanted to make sure I was using generics correctly, though I don't think I am.

can an arraylist hold a table of items similiar to the results of a mysql request? I've got 5 items coming out of the request, and from everything I see about ArrayList, it gives you a an "id" column and an "item" column...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.