Files
DEV/DEV3.1/base_donne/Vote.java

47 lines
1.6 KiB
Java

import java.sql.*;
public class Vote{
public static void main (String[] arg){
try{
Class.forName("org.mariadb.jdbc.Driver");
}catch(ClassNotFoundException e){
System.err.println("pas de disponibilité");
System.exit(1);
}
try{
Connection bd = DriverManager.getConnection(
"jdbc:mariadb://dwarves.iut-fbleau.fr/felix-vi",
"felix-vi", "felix-vi");
try{
PreparedStatement pst = bd.prepareStatement(
"SELECT votants, points FROM Vote WHERE competiteur = ?");
pst.setString(1, arg[0]);
ResultSet rs = pst.executeQuery();
try{
int total = 0;
while(rs.next()) {
total += rs.getInt(2);
System.out.print(rs.getString(1));
System.out.print(" ");
System.out.println(rs.getInt(2));
}
System.out.print("Total ");
System.out.println(total);
rs.close();
}catch(SQLException e){
System.err.println("mal affichage");
System.exit(1);
}
pst.close();
}catch(SQLException e){
System.err.println("mal execute");
System.exit(1);
}
bd.close();
}catch(SQLException e){
System.err.println("mauvais mdp");
System.exit(1);
}
}
}