2023-09-20 12:11:33 +02:00
|
|
|
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
|
|
|
|
{
|
2023-11-22 16:37:13 +01:00
|
|
|
Class.forName("org.mariadb.jdbc.Driver");
|
2023-09-20 12:11:33 +02:00
|
|
|
Connection cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/sayebabu","sayebabu", "kjrzB5S4kqKAwdT");
|
|
|
|
try
|
|
|
|
{
|
2023-11-22 16:37:13 +01:00
|
|
|
PreparedStatement pst = cnx.prepareStatement("SELECT PaysID FROM `Pays` WHERE Pays = ?");
|
2023-09-20 12:11:33 +02:00
|
|
|
pst.setString(1, args[0]);
|
|
|
|
ResultSet rs = pst.executeQuery();
|
|
|
|
int paysID = rs.getInt(1);
|
2023-11-22 16:37:13 +01:00
|
|
|
pst = cnx.prepareStatement("SELECT PaysVoteID, Points FROM `Comp` WHERE PaysCompID = ?");
|
2023-09-20 12:11:33 +02:00
|
|
|
pst.setInt(1, paysID);
|
|
|
|
|
|
|
|
int sumVote = 0;
|
|
|
|
while(rs.next())
|
|
|
|
{
|
|
|
|
int comp = rs.getInt(1);
|
|
|
|
int votants = rs.getInt(2);
|
|
|
|
sumVote+=votants;
|
|
|
|
|
2023-11-22 16:37:13 +01:00
|
|
|
PreparedStatement pst2 = cnx.prepareStatement("SELECT Pays FROM `Pays` WHERE PaysID = ?");
|
2023-09-20 12:11:33 +02:00
|
|
|
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();
|
2023-11-22 16:37:13 +01:00
|
|
|
System.out.printf("TA MERE2"+e);
|
2023-09-20 12:11:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2023-11-22 16:37:13 +01:00
|
|
|
System.out.printf("TA MERE1"+ e);
|
2023-09-20 12:11:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|