57 lines
1.4 KiB
Java
57 lines
1.4 KiB
Java
|
import org.mariadb.jdbc.*;
|
||
|
|
||
|
public class Q1Main{
|
||
|
public static void main(String[] args) {
|
||
|
if (args.length < 1){
|
||
|
System.out.println("Arguments invalide");
|
||
|
return 0;
|
||
|
}
|
||
|
String pays = args[0];
|
||
|
try{
|
||
|
Connection cnx = DriverManager.getConnection(
|
||
|
"jdbc:mariadb://dwarves.iut-fbleau.fr/wamster",
|
||
|
"wamster","...");
|
||
|
try {
|
||
|
Class.forName("org.mariadb.jdbc.Driver");
|
||
|
}
|
||
|
catch(ClassNotFoundException){
|
||
|
System.out.println("ClassNotFoundException");
|
||
|
cnx.close();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
// récupération de l'id du pays entrée en ligne de commande
|
||
|
PreparedStatement pst = cnx.prepareStatement(
|
||
|
"SELECT idPays FROM DEV31TP01Q1_ListePays WHERE nomPays=?");
|
||
|
pst.setString(1, pays);
|
||
|
ResultSet rs = pst.executeQuery();
|
||
|
pst.close();
|
||
|
int idPays = null;
|
||
|
if (rs.next()){
|
||
|
idPays = rs;
|
||
|
}
|
||
|
rs.close();
|
||
|
if (idPays == null){
|
||
|
System.out.println("Pays inconnus");
|
||
|
return 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);
|
||
|
}
|
||
|
rs.close();
|
||
|
pst.close();
|
||
|
|
||
|
}
|
||
|
catch(SQLException){
|
||
|
System.out.println("SQLException");
|
||
|
cnx.close();
|
||
|
}
|
||
|
}
|
||
|
}
|