package br.dsc.upe.poli.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;

import br.dsc.upe.poli.banco.ConexaoFactory;
import br.dsc.upe.poli.basicas.Resposta;
public class RespostaAlunoDAO {
	
	
	
	private Connection connection;

	public RespostaAlunoDAO() throws ClassNotFoundException, SQLException {
		this.connection = new ConexaoFactory().getConexao();
	}
	
	public void cadastrar(Resposta resposta) throws SQLException {
		PreparedStatement stmt=connection.prepareStatement("INSERT INTO resposta (atividade, login, pergunta, resposta ) VALUES (?,?,?,?)");
		HashMap<String, String> perguntas_respostas = resposta.getPerguntas_respostas();
		Iterator<String> iterator = perguntas_respostas.keySet().iterator();
		while (iterator.hasNext()) {
			String pergunta = (String) iterator.next();
			stmt.setString(1, resposta.getNomeAtividade());
			stmt.setString(2, resposta.getLogin());
			stmt.setString(3, pergunta);
			stmt.setString(4, perguntas_respostas.get(pergunta));
			stmt.executeUpdate();

		}
		
		
		stmt.close();
	}



	

}
