septembre + octobre

This commit is contained in:
2023-10-12 16:39:49 +02:00
commit 06bf5f9488
389 changed files with 4233 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
alias javacdb='javac -cp ".:/export/documents/mariadb-client.jar"'
alias javadb='java -cp ".:/export/documents/mariadb-client.jar"'

View File

@@ -0,0 +1 @@
alias javacdb='java -cp ".:/export/documents/mariadb-client.jar"'

Binary file not shown.

View File

@@ -0,0 +1,116 @@
import org.mariadb.jdbc.*;
import java.sql.*;
public class Q1Main{
public static void main(String[] args) {
if (args.length < 1){
System.out.println("Arguments invalide");
System.exit(0);
}
String pays = args[0];
try{
int idPays = -1;
Connection cnx = DriverManager.getConnection(
"jdbc:mariadb://dwarves.iut-fbleau.fr/wamster",
"wamster","32201909");
try {
Class.forName("org.mariadb.jdbc.Driver");
}
catch(ClassNotFoundException e){
System.out.println("ClassNotFoundException");
cnx.close();
System.exit(0);
}
// recuperation de l'id du pays entree en ligne de commande
try {
PreparedStatement pst = cnx.prepareStatement(
"SELECT idPays FROM DEV31TP01Q1_ListePays WHERE nomPays=?");
pst.setString(1, pays);
ResultSet rs = pst.executeQuery();
pst.close();
if (rs.next()){
idPays = rs.getInt("idPays");
}
rs.close();
if (idPays == -1){
System.out.println("Pays inconnus");
System.exit(0);
}
}
catch(SQLException e){
System.out.println("probleme de select 1");
cnx.close();
System.exit(0);
}
// recuperation des score du pays
try {
PreparedStatement pst = cnx.prepareStatement(
"SELECT * FROM DEV31TP01Q1_score WHERE idCompetiteurs=?");
pst.setInt(1, idPays);
ResultSet rsid = pst.executeQuery();
pst.close();
int scoreTotal = 0;
//recuperation du nom du votant à partir de son id
try{
pst = cnx.prepareStatement(
"SELECT nomPays FROM DEV31TP01Q1_ListePays WHERE idPays=?");
while (rsid.next()){
int idVotant = rsid.getInt("idVotants");
int score = rsid.getInt("score");
String nomVotant = null;
pst.setInt(1, idVotant);
ResultSet rsnom = pst.executeQuery();
if (rsnom.next()){
nomVotant = rsnom.getString("NomPays");
}
rsnom.close();
// affichage du score qu'a donne le votant (aligner proprement)
System.out.print(nomVotant);
int espaceAAjouter = 20 - (nomVotant.length() + Integer.toString(score).length());
for (int i=0; i<espaceAAjouter; i++){
System.out.print(" ");
}
System.out.println(score);
scoreTotal += score;
}
pst.close();
rsid.close();
//affichage du score total
for (int i=0; i<17; i++){
System.out.print(" ");
}
System.out.println("___");
int espaceAAjouter = 20 - ("Total".length() + Integer.toString(scoreTotal).length());
System.out.print("Total");
for (int i=0; i<espaceAAjouter; i++){
System.out.print(" ");
}
System.out.println(scoreTotal);
}
catch(SQLException e){
System.out.println("probleme de select ?");
cnx.close();
System.exit(0);
}
}
catch(SQLException e){
System.out.println("probleme de select 2");
cnx.close();
System.exit(0);
}
cnx.close();
}
catch(SQLException e){
System.out.println("SQLException");
}
}
}

View File

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

Binary file not shown.

View File

@@ -0,0 +1,64 @@
import org.mariadb.jdbc.*;
import java.sql.*;
public class Q2BestPays{
public static String[] bestPays() {
try{
int idPays = -1;
String nomPays = null;
String bestPays = null;
int score = 0;
int bestScore = 0;
Connection cnx = DriverManager.getConnection(
"jdbc:mariadb://dwarves.iut-fbleau.fr/wamster",
"wamster","32201909");
try {
Class.forName("org.mariadb.jdbc.Driver");
}
catch(ClassNotFoundException e){
cnx.close();
return null;
}
try {
PreparedStatement pstCompetiteur = cnx.prepareStatement(
"SELECT * FROM DEV31TP01Q1_ListePays");
ResultSet rsCompetiteur = pstCompetiteur.executeQuery();
while (rsCompetiteur.next()){
idPays = rsCompetiteur.getInt("idPays");
nomPays = rsCompetiteur.getString("NomPays");
score = 0;
PreparedStatement pstScore = cnx.prepareStatement(
"SELECT score FROM DEV31TP01Q1_score WHERE idCompetiteurs=?");
pstScore.setInt(1, idPays);
ResultSet rsScore = pstScore.executeQuery();
pstScore.close();
while (rsScore.next()){
score += rsScore.getInt("score");
}
rsScore.close();
if (score > bestScore){
bestScore = score;
bestPays = nomPays;
}
}
rsCompetiteur.close();
pstCompetiteur.close();
if (idPays == -1){
cnx.close();
return null;
}
cnx.close();
return new String[] {bestPays, Integer.toString(bestScore)};
}
catch(SQLException e){
cnx.close();
return null;
}
}
catch(SQLException e){
return null;
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,22 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Q2Evenement implements ActionListener{
public JLabel pays;
public JLabel score;
public Q2Evenement(JLabel pays, JLabel score){
this.pays = pays;
this.score = score;
}
@Override
public void actionPerformed(ActionEvent evenement){
String[] bestPays = Q2BestPays.bestPays();
if (bestPays != null){
this.pays.setText(bestPays[0]);
this.score.setText(bestPays[1]);
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,35 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Q2Main{
public static void main(String[] args) {
JFrame fenetre = new JFrame("Question 2");
fenetre.setSize(300, 200);
fenetre.setLocation(700, 300);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel labelPays = new JLabel("", JLabel.CENTER);
JLabel labelScore = new JLabel("", JLabel.CENTER);
JButton bouton = new JButton("o");
JPanel bas = new JPanel(new BorderLayout());
bas.add(bouton,BorderLayout.EAST);
String[] bestPays = Q2BestPays.bestPays();
if (bestPays != null){
labelPays.setText(bestPays[0]);
labelScore.setText(bestPays[1]);
}
fenetre.add(labelPays, BorderLayout.NORTH);
fenetre.add(labelScore, BorderLayout.CENTER);
fenetre.add(bas, BorderLayout.SOUTH);
Q2Evenement evenementBouton = new Q2Evenement(labelPays, labelScore);
bouton.addActionListener(evenementBouton);
fenetre.setVisible(true);
}
}

View File

@@ -0,0 +1,56 @@
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();
}
}
}

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Some files were not shown because too many files have changed in this diff Show More