57 lines
1.8 KiB
Java
57 lines
1.8 KiB
Java
import java.sql.Connection;
|
|
import java.sql.DriverManager;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
|
|
|
|
public class vote
|
|
{
|
|
public static void main(String[] args)
|
|
{
|
|
|
|
try
|
|
{
|
|
Class.forName("org.mariadb.jdbc.Driver");
|
|
Connection cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/sayebabu","sayebabu", "kjrzB5S4kqKAwdT");
|
|
try
|
|
{
|
|
PreparedStatement pst = cnx.prepareStatement("SELECT PaysID FROM `Pays` WHERE Pays = ?");
|
|
pst.setString(1, args[0]);
|
|
ResultSet rs = pst.executeQuery();
|
|
int paysID = rs.getInt(1);
|
|
pst = cnx.prepareStatement("SELECT PaysVoteID, Points FROM `Comp` WHERE PaysCompID = ?");
|
|
pst.setInt(1, paysID);
|
|
|
|
int sumVote = 0;
|
|
while(rs.next())
|
|
{
|
|
int comp = rs.getInt(1);
|
|
int votants = rs.getInt(2);
|
|
sumVote+=votants;
|
|
|
|
PreparedStatement pst2 = cnx.prepareStatement("SELECT Pays FROM `Pays` WHERE PaysID = ?");
|
|
pst2.setInt(1, comp);
|
|
ResultSet rs2 = pst.executeQuery();
|
|
rs2.next();
|
|
String PaysName = rs2.getString(1);
|
|
|
|
|
|
System.out.printf("%20s,%f \n",PaysName,votants);
|
|
}
|
|
System.out.printf("%20s --- \n", " ");
|
|
System.out.printf("%20s %f \n", "Total",sumVote);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
cnx.close();
|
|
System.out.printf("TA MERE2"+e);
|
|
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
System.out.printf("TA MERE1"+ e);
|
|
}
|
|
}
|
|
}
|