Files
DEV/DEV.3.1/TP/TP1/Vote.java
EmmanuelTiamzon 016c70aab4 update
2025-10-14 14:41:43 +02:00

52 lines
1.3 KiB
Java

import java.sql.*;
public class Vote {
private String[] pays;
public Vote(String[] pays) {
this.pays = pays;
if (pays.length == 0) {
System.err.println("Aucun pays compétiteur fourni.");
return;
}
try{
Connection cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/srivasta","login", "mdp");
try{
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);
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);
}
} catch(SQLException e) {
System.err.println("Erreur de connexion : "+e);
}
}
}