package donnee;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import modele.Exoplanete;

public class ExoplanetesDAO {

	public List<Exoplanete> listerExoplanetes()
	{
		System.out.println("ExoplanetesDAO.listerExoplanetes()");
		
		Connection connection = BaseDeDonnees.getInstance().getConnection();
		
		List<Exoplanete> listeExoplanetes =  new ArrayList<Exoplanete>();			
		Statement requeteListeExoplanetes;
		try {
			requeteListeExoplanetes = connection.createStatement();
			ResultSet curseurListeExoplanetes = requeteListeExoplanetes.executeQuery("SELECT * from exoplanete");
			while(curseurListeExoplanetes.next())
			{
				//int id = curseurListeEtudiants.getInt("id");
				String nom = curseurListeExoplanetes.getString("planete");
				String etoile = curseurListeExoplanetes.getString("etoile");
				String masse = curseurListeExoplanetes.getString("masse");
				String rayon = curseurListeExoplanetes.getString("rayon");
				String flux = curseurListeExoplanetes.getString("flux");
				String temperature = curseurListeExoplanetes.getString("temperature");
				String periode = curseurListeExoplanetes.getString("periode");
				String distance = curseurListeExoplanetes.getString("distance");
				
				Exoplanete exoplanete = new Exoplanete();
				//exoplanete.setId(id);
				exoplanete.setNom(nom);
				exoplanete.setEtoile(etoile);
				exoplanete.setMasse(masse);
				exoplanete.setRayon(rayon);
				exoplanete.setFlux(flux);
				exoplanete.setTemperature(temperature);
				exoplanete.setPeriode(periode);
				exoplanete.setDistance(distance);
				
				listeExoplanetes.add(exoplanete);
			}
		} catch (SQLException e) {
				e.printStackTrace();
		}
		
		return listeExoplanetes;
	}
}