wow le tp là
This commit is contained in:
56
DEV3.1/TP01/02_Victoire/Connexion.java
Normal file
56
DEV3.1/TP01/02_Victoire/Connexion.java
Normal file
@@ -0,0 +1,56 @@
|
||||
import org.mariadb.jdbc.*;
|
||||
import javax.swing.*;
|
||||
import java.sql.*;
|
||||
|
||||
public class Connexion {
|
||||
|
||||
private int scoreMax;
|
||||
private String paysMax;
|
||||
|
||||
public Connexion() {
|
||||
try {
|
||||
Connection cnx = DriverManager.getConnection(
|
||||
"jdbc:mariadb://dwarves.iut-fbleau.fr/simoes",
|
||||
"simoes", "simoes"
|
||||
);
|
||||
|
||||
try {
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e2) {
|
||||
System.err.println("Problème de pilote.");
|
||||
}
|
||||
|
||||
try {
|
||||
PreparedStatement pst = cnx.prepareStatement(
|
||||
"SELECT SUM(points), competiteur FROM pays GROUP BY competiteur ASC;"
|
||||
);
|
||||
|
||||
ResultSet rs = pst.executeQuery();
|
||||
|
||||
int total = 0;
|
||||
|
||||
rs.next();
|
||||
|
||||
this.scoreMax = rs.getInt(1);
|
||||
this.paysMax = rs.getString(2);
|
||||
|
||||
rs.close();
|
||||
pst.close();
|
||||
} catch (SQLException e3) {
|
||||
System.err.println("Erreur de syntaxe SQL.");
|
||||
}
|
||||
|
||||
cnx.close();
|
||||
} catch (SQLException e1) {
|
||||
System.err.println("Erreur de connexion à la base de données.");
|
||||
}
|
||||
}
|
||||
|
||||
public String getNomPays() {
|
||||
return this.paysMax;
|
||||
}
|
||||
|
||||
public int getScorePays() {
|
||||
return this.scoreMax;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user