package fonctions;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import retro.Affiliate;
import retro.DBConnexion;

public class AffiliateDAO {
	
public void insert_affiliate(String id_meeting, String id_member){
		

		Connection connection= DBConnexion.getConnection();
		PreparedStatement ps=null;
		
		try {	
		
		String query="insert into affiliate(id_meeting, id_member) values(?,?)";
		 ps=connection.prepareStatement(query);
		 ps.setString(1, id_meeting);
		 ps.setString(2, id_member);
		 ps.executeUpdate();
		 		 
		 
		} catch (Exception e) {
			System.err.println(e);
		}
	}


public static void main(String[] args) {
	IdeaDAO obj_ReadValues=new IdeaDAO();
	
	obj_ReadValues.get_values();
}



public List<Affiliate> get_values(){

	Connection connection= DBConnexion.getConnection();
	
	PreparedStatement ps=null;
	ResultSet rs=null;
	 List<Affiliate> list=new ArrayList<Affiliate>();
	
	try {
		String querry="SELECT * FROM affiliate";
		ps=connection.prepareStatement(querry);	

		rs=ps.executeQuery();		
		
		while(rs.next()){
			
			Affiliate obj_Affiliate=new Affiliate();
			System.out.println(rs.getInt("id_meeting"));
			System.out.println(rs.getString("id_member"));

			
			obj_Affiliate.setId_meeting(rs.getString("id_meeting"));
			obj_Affiliate.setId_member(rs.getString("id_member"));

			list.add(obj_Affiliate);				
		}						
	} catch (Exception e) {
			System.out.println(e);
	}
	return list;
}




public void delete_affiliate(String id_member, String id_meeting){

	Connection connection= DBConnexion.getConnection();
	
	PreparedStatement ps=null;
	 
	try {
		String querry="delete from affiliate where id_member= ? and id_meeting = ?";
		ps=connection.prepareStatement(querry);		
		ps.setString(1, id_member);;
		ps.setString(2, id_meeting);;
		ps.executeUpdate();
		
	} catch (Exception e) {
			System.out.println(e);
	}
	 	
}


}
