update
This commit is contained in:
BIN
DEV.3.1/TP/TP1/Main.class
Normal file
BIN
DEV.3.1/TP/TP1/Main.class
Normal file
Binary file not shown.
5
DEV.3.1/TP/TP1/Main.java
Normal file
5
DEV.3.1/TP/TP1/Main.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Vote vote = new Vote();
|
||||||
|
}
|
||||||
|
}
|
BIN
DEV.3.1/TP/TP1/MonProgramme.class
Normal file
BIN
DEV.3.1/TP/TP1/MonProgramme.class
Normal file
Binary file not shown.
@@ -1,4 +1,5 @@
|
|||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
import org.mariadb.jdbc.*;
|
||||||
|
|
||||||
public class MonProgramme {
|
public class MonProgramme {
|
||||||
|
|
||||||
@@ -6,11 +7,22 @@ public class MonProgramme {
|
|||||||
try {
|
try {
|
||||||
Connection cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/srivasta","srivasta", "Tiamzon2006");
|
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(1, 50);
|
||||||
pst.setInt(2, 100);
|
pst.setInt(2, 100);
|
||||||
ResultSet rs = pst.executeQuery();
|
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) {
|
}catch(SQLException e) {
|
||||||
System.err.println("Connexion echouee : "+e);
|
System.err.println("Connexion echouee : "+e);
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@@ -4,22 +4,35 @@ public class Vote {
|
|||||||
|
|
||||||
private String[] pays;
|
private String[] pays;
|
||||||
|
|
||||||
public Vote(String[] args) {
|
public Vote(String[] pays) {
|
||||||
this.pays = pays;
|
this.pays = pays;
|
||||||
|
|
||||||
|
if (pays.length == 0) {
|
||||||
|
System.err.println("Aucun pays compétiteur fourni.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
Connection cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/srivasta","srivasta", "Tiamzon2006");
|
Connection cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/srivasta","srivasta", "Tiamzon2006");
|
||||||
|
|
||||||
try{
|
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)+" ");
|
String query = "SELECT Votants, Points FROM tp1_points WHERE Compétiteur = ?";
|
||||||
System.out.print(rs.getString(1)+" ");
|
PreparedStatement req = cnx.prepareStatement(query);
|
||||||
System.out.println(rs.getInt(3));
|
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{
|
try{
|
||||||
rs.close();
|
rs.close();
|
||||||
@@ -36,9 +49,4 @@ public class Vote {
|
|||||||
System.err.println("Erreur de connexion : "+e);
|
System.err.println("Erreur de connexion : "+e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Vote vote = new Vote(args);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user