66 lines
1.6 KiB
Java
66 lines
1.6 KiB
Java
|
import org.mariadb.jdbc.*;
|
||
|
import java.sql.*;
|
||
|
|
||
|
public class Q1Main{
|
||
|
public static void main(String[] args) {
|
||
|
if (args.length < 1){
|
||
|
System.out.println("Arguments invalide");
|
||
|
System.exit(0);
|
||
|
}
|
||
|
String pays = args[0];
|
||
|
try{
|
||
|
Connection cnx = DriverManager.getConnection(
|
||
|
"jdbc:mariadb://dwarves.iut-fbleau.fr/wamster",
|
||
|
"wamster","32201909");
|
||
|
try {
|
||
|
Class.forName("org.mariadb.jdbc.Driver");
|
||
|
}
|
||
|
catch(ClassNotFoundException e){
|
||
|
System.out.println("ClassNotFoundException");
|
||
|
cnx.close();
|
||
|
System.exit(0);
|
||
|
}
|
||
|
|
||
|
|
||
|
// récupération de l'id du pays entrée en ligne de commande
|
||
|
try {
|
||
|
PreparedStatement pst = cnx.prepareStatement(
|
||
|
"SELECT idPays FROM DEV31TP01Q1_ListePays WHERE nomPays=?");
|
||
|
pst.setString(1, pays);
|
||
|
ResultSet rs = pst.executeQuery();
|
||
|
pst.close();
|
||
|
int idPays = -1;
|
||
|
if (rs.next()){
|
||
|
idPays = rs.getInt("idPays");
|
||
|
}
|
||
|
rs.close();
|
||
|
if (idPays == -1){
|
||
|
System.out.println("Pays inconnus");
|
||
|
System.exit(0);
|
||
|
}
|
||
|
}
|
||
|
catch(SQLException e){
|
||
|
System.out.println("problème de select 1");
|
||
|
cnx.close();
|
||
|
System.exit(0);
|
||
|
}
|
||
|
|
||
|
// récupération des score du pays
|
||
|
PreparedStatement pst = cnx.prepareStatement(
|
||
|
"SELECT * FROM DEV31TP01Q1_score WHERE idCompetiteurs=?");
|
||
|
pst.setInt(1, idPays);
|
||
|
ResultSet rs = pst.executeQuery();
|
||
|
while (rs.next()){
|
||
|
System.out.println(rs.getInt("idCompetiteurs")+" "+rs.getInt("idVotants")+" "+rs.getInt("score"));
|
||
|
}
|
||
|
rs.close();
|
||
|
pst.close();
|
||
|
cnx.close();
|
||
|
|
||
|
}
|
||
|
catch(SQLException e){
|
||
|
System.out.println("SQLException");
|
||
|
}
|
||
|
}
|
||
|
}
|