2025-09-05 19:30:04 +02:00
|
|
|
import java.sql.*;
|
|
|
|
|
|
|
|
public class Vote {
|
|
|
|
|
2025-09-16 10:27:52 +02:00
|
|
|
private String[] pays;
|
2025-09-05 19:45:08 +02:00
|
|
|
|
2025-09-30 12:30:40 +02:00
|
|
|
public Vote(String[] pays) {
|
2025-09-05 19:30:04 +02:00
|
|
|
this.pays = pays;
|
2025-09-05 19:45:08 +02:00
|
|
|
|
2025-09-30 12:30:40 +02:00
|
|
|
if (pays.length == 0) {
|
|
|
|
System.err.println("Aucun pays compétiteur fourni.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-09-05 19:45:08 +02:00
|
|
|
try{
|
|
|
|
Connection cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/srivasta","srivasta", "Tiamzon2006");
|
|
|
|
|
2025-09-16 12:27:47 +02:00
|
|
|
try{
|
2025-09-30 12:30:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
String query = "SELECT Votants, Points FROM tp1_points WHERE Compétiteur = ?";
|
|
|
|
PreparedStatement req = cnx.prepareStatement(query);
|
|
|
|
req.setString(1, competiteur);
|
|
|
|
|
|
|
|
ResultSet rs = req.executeQuery();
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
String votant = rs.getString("Votants");
|
|
|
|
int points = rs.getInt("Points");
|
|
|
|
System.out.printf("%-10s %3d%n", votant, points);
|
|
|
|
total += points;
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println(" ---");
|
|
|
|
System.out.printf("Total %3d%n", total);
|
2025-09-16 12:27:47 +02:00
|
|
|
|
|
|
|
try{
|
|
|
|
rs.close();
|
|
|
|
req.close();
|
|
|
|
cnx.close();
|
|
|
|
|
|
|
|
}catch(SQLException e) {
|
|
|
|
System.err.println("Erreur de connexion : "+e);
|
|
|
|
}
|
|
|
|
}catch(SQLException e) {
|
|
|
|
System.err.println("Erreur SQL ou de connexion : "+e);
|
|
|
|
}
|
2025-09-05 19:45:08 +02:00
|
|
|
} catch(SQLException e) {
|
|
|
|
System.err.println("Erreur de connexion : "+e);
|
|
|
|
}
|
2025-09-05 19:30:04 +02:00
|
|
|
}
|
|
|
|
}
|