52 lines
1.1 KiB
Java
52 lines
1.1 KiB
Java
![]() |
import org.mariadb.jdbc.*;
|
||
|
import java.awt.*;
|
||
|
import java.sql.*;
|
||
|
|
||
|
public class Vote {
|
||
|
|
||
|
private String competiteur;
|
||
|
|
||
|
public Vote(String competiteur) {
|
||
|
this.competiteur = competiteur;
|
||
|
|
||
|
try {
|
||
|
Connection cnx = DriverManager.getConnection(
|
||
|
"jdbc:mariadb://dwarves.iut-fbleau.fr/simoes",
|
||
|
"simoes", "simoes"
|
||
|
);
|
||
|
|
||
|
try {
|
||
|
Class.forName("org.mariadb.jdbc.Driver");
|
||
|
} catch (ClassNotFoundException e2) {
|
||
|
System.err.println("Problème de pilote.");
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
PreparedStatement pst = cnx.prepareStatement(
|
||
|
"SELECT votants, points FROM pays WHERE competiteur = '" + this.competiteur + "';"
|
||
|
);
|
||
|
|
||
|
ResultSet rs = pst.executeQuery();
|
||
|
|
||
|
int total = 0;
|
||
|
|
||
|
while (rs.next()) {
|
||
|
total += rs.getInt(2);
|
||
|
System.out.println(rs.getString(1) + " " + rs.getInt(2));
|
||
|
}
|
||
|
|
||
|
System.out.println("---------");
|
||
|
System.out.println("Total " + total);
|
||
|
|
||
|
rs.close();
|
||
|
pst.close();
|
||
|
} catch (SQLException e3) {
|
||
|
System.err.println("Erreur de syntaxe SQL.");
|
||
|
}
|
||
|
|
||
|
cnx.close();
|
||
|
} catch (SQLException e1) {
|
||
|
System.err.println("Erreur de connexion à la base de données.");
|
||
|
}
|
||
|
}
|
||
|
}
|