This commit is contained in:
EmmanuelTiamzon
2025-09-30 12:30:40 +02:00
parent 07d07c2af1
commit 60fa34b04f
6 changed files with 40 additions and 15 deletions

BIN
DEV.3.1/TP/TP1/Main.class Normal file

Binary file not shown.

5
DEV.3.1/TP/TP1/Main.java Normal file
View File

@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
Vote vote = new Vote();
}
}

Binary file not shown.

View File

@@ -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);
}

Binary file not shown.

View File

@@ -4,23 +4,36 @@ 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 = "(?)";");
String query = "SELECT Votants, Points FROM tp1_points WHERE Compétiteur = ?";
PreparedStatement req = cnx.prepareStatement(query);
req.setString(1, competiteur);
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 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();
req.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);
}
}