import org.mariadb.jdbc.*; import java.sql.*; public class Vote{ public static void main(String[] args) { int total = 0; try{ Class.forName("org.mariadb.jdbc.Driver"); try{ Connection cnx = DriverManager.getConnection( "jdbc:mariadb://dwarves.iut-fbleau.fr/pourchot", "pourchot", "supermotdepasseultrafort"); try{ PreparedStatement pst = cnx.prepareStatement( "SELECT p1.nom, p2.nom, v.Points FROM Vote v " +"LEFT JOIN Pays p1 ON v.Competiteur = p1.Id " +"LEFT JOIN Pays p2 ON v.Votants = p2.Id " +"WHERE p1.nom = (?);"); pst.setString(1, args[0]); ResultSet rs = pst.executeQuery(); while(rs.next()) { System.out.println(rs.getString(2)+" "+" "+rs.getInt(3)); total+=rs.getInt(3); } System.out.println(" ---"); System.out.println("Total "+total); rs.close(); pst.close(); cnx.close(); //System.out.println(rs.isClosed()); //System.out.println(pst.isClosed()); //System.out.println(cnx.isClosed()); } catch (SQLException e){ System.err.println("Requête échoué"); cnx.close(); //System.out.println(cnx.isClosed()); } } catch (SQLException e){ System.err.println("Connexion à la base de donnée échouée"); } } catch (ClassNotFoundException e){ System.err.println("Mauvais classpath"); } } }