diff --git a/DEV.3.1/TP/TP1/Main.class b/DEV.3.1/TP/TP1/Main.class new file mode 100644 index 0000000..6e2ff84 Binary files /dev/null and b/DEV.3.1/TP/TP1/Main.class differ diff --git a/DEV.3.1/TP/TP1/Main.java b/DEV.3.1/TP/TP1/Main.java new file mode 100644 index 0000000..90222cf --- /dev/null +++ b/DEV.3.1/TP/TP1/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + Vote vote = new Vote(); + } +} \ No newline at end of file diff --git a/DEV.3.1/TP/TP1/MonProgramme.class b/DEV.3.1/TP/TP1/MonProgramme.class new file mode 100644 index 0000000..a41f144 Binary files /dev/null and b/DEV.3.1/TP/TP1/MonProgramme.class differ diff --git a/DEV.3.1/TP/TP1/MonProgramme.java b/DEV.3.1/TP/TP1/MonProgramme.java index ce30cba..5c63e29 100644 --- a/DEV.3.1/TP/TP1/MonProgramme.java +++ b/DEV.3.1/TP/TP1/MonProgramme.java @@ -1,4 +1,5 @@ import java.sql.*; +import org.mariadb.jdbc.*; public class MonProgramme { @@ -6,11 +7,22 @@ public class MonProgramme { try { Connection cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/srivasta","srivasta", "Tiamzon2006"); - PreparedStatement pst = cnx.prepareStatement("SELECT valeur FROM Mesure WHERE valeur BETWEEN ? AND ?"); + PreparedStatement pst = cnx.prepareStatement("SELECT name FROM episode WHERE id BETWEEN ? AND ?"); pst.setInt(1, 50); pst.setInt(2, 100); ResultSet rs = pst.executeQuery(); + while(rs.next()) { + String name = rs.getString("name"); + System.out.println("Episode: " + name); + } + + // Fermeture des ressources + rs.close(); + pst.close(); + cnx.close(); + + }catch(SQLException e) { System.err.println("Connexion echouee : "+e); } diff --git a/DEV.3.1/TP/TP1/Vote.class b/DEV.3.1/TP/TP1/Vote.class index f488f90..71c8d04 100644 Binary files a/DEV.3.1/TP/TP1/Vote.class and b/DEV.3.1/TP/TP1/Vote.class differ diff --git a/DEV.3.1/TP/TP1/Vote.java b/DEV.3.1/TP/TP1/Vote.java index 099c774..29d2624 100644 --- a/DEV.3.1/TP/TP1/Vote.java +++ b/DEV.3.1/TP/TP1/Vote.java @@ -4,22 +4,35 @@ public class Vote { private String[] pays; - public Vote(String[] args) { + public Vote(String[] pays) { this.pays = pays; + if (pays.length == 0) { + System.err.println("Aucun pays compétiteur fourni."); + return; + } + try{ Connection cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/srivasta","srivasta", "Tiamzon2006"); try{ - PreparedStatement req = cnx.prepareStatement("SELECT Votants, Points FROM tp1_points WHERE Compétiteur = "(?)";"); - ResultSet rs = req.executeQuery(); - req.setString(1, this.pays); + - while(rs.next()) { - System.out.print(rs.getInt(2)+" "); - System.out.print(rs.getString(1)+" "); - System.out.println(rs.getInt(3)); - } + String query = "SELECT Votants, Points FROM tp1_points WHERE Compétiteur = ?"; + PreparedStatement req = cnx.prepareStatement(query); + req.setString(1, competiteur); + + ResultSet rs = req.executeQuery(); + + while (rs.next()) { + String votant = rs.getString("Votants"); + int points = rs.getInt("Points"); + System.out.printf("%-10s %3d%n", votant, points); + total += points; + } + + System.out.println(" ---"); + System.out.printf("Total %3d%n", total); try{ rs.close(); @@ -36,9 +49,4 @@ public class Vote { System.err.println("Erreur de connexion : "+e); } } - - public static void main(String[] args) { - Vote vote = new Vote(args); - - } } \ No newline at end of file