Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package fr.btssnir;
- import clavier.In;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- /**
- *
- * @author bbrancourt
- */
- public class BRANCOURT_Bastien_TP_Biblio {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws ClassNotFoundException, SQLException {
- int menu;
- ArrayList<Livre> listLivre = new ArrayList();
- ArrayList<Client> listClient = new ArrayList();
- ArrayList<Location> listLocation = new ArrayList();
- Class.forName("com.mysql.jdbc.Driver");
- Connection connexion = DriverManager.getConnection("jdbc:mysql://localhost/bibliothèque", "root", "");
- Statement etat = connexion.createStatement();
- ResultSet rs = null;
- System.out.println("Selectionnez votre choix:\n\n 1. Afficher la liste des livres\t2. Afficher la liste des clients\n 3. Afficher la liste des locations");
- menu = In.readInteger();
- switch (menu) {
- case 1:
- rs = etat.executeQuery("SELECT * from livre");
- while (rs.next()) {
- Livre l = new Livre(rs.getInt("id_livre"), rs.getString("code_barre"), rs.getString("titre"), rs.getString("auteur"), rs.getString("genre"), rs.getString("résumé"));
- listLivre.add(l);
- }
- for (Livre li : listLivre) {
- System.out.println("\nCODE BARRE : " + li.getCode_barre() + "\nAUTEUR : " + li.getAuteur() + "\nTITRE : " + li.getTitre() + "\nGENRE : " + li.getGenre() + "\nRESUME : " + li.getRésumé());
- }
- break;
- case 2:
- rs = etat.executeQuery("SELECT * from client");
- while (rs.next()) {
- Client c = new Client(rs.getInt("id_client"), rs.getInt("numero_client"), rs.getString("nom"), rs.getString("prenom"), rs.getString("adresse"), rs.getString("téléphone"));
- listClient.add(c);
- }
- for (Client cl : listClient) {
- System.out.println("\nNUMERO CLIENT : " + cl.getNumero_client() + "\n\nNOM : " + cl.getNom() + "\nPRENOM : " + cl.getPrenom() + "\nADRESSE : " + cl.getAdresse() + "\nTELEPHONE : " + cl.getTéléphone());
- }
- break;
- case 3:
- rs = etat.executeQuery("SELECT * from location loc join livre l join client c on loc.id_client = c.id_client and loc.id_livre = l.id_livre");
- while (rs.next()) {
- Livre l = new Livre(rs.getInt("id_livre"), rs.getString("code_barre"), rs.getString("titre"), rs.getString("auteur"), rs.getString("genre"), rs.getString("résumé"));
- Client c = new Client(rs.getInt("id_client"), rs.getInt("numero_client"), rs.getString("nom"), rs.getString("prenom"), rs.getString("adresse"), rs.getString("téléphone"));
- Location loc = new Location(rs.getInt("id_location"), c, l, rs.getDate("date_emprunt"), rs.getDate("date_retour"));
- listLocation.add(loc);
- }
- for (Location loca : listLocation) {
- if (loca.getDate_retour() == null) {
- System.out.println("LOCATION : " + loca.getId_location() + " DATE EMPRUNT : " + loca.getDate_emprunt() + " DATE RETOUR : ????");
- System.out.println("CLIENT : " + loca.getClient().getNom() + " " + loca.getClient().getPrenom());
- System.out.println("LIVRE :\t\"" + loca.getLivre().getTitre().toUpperCase() + "\" de " + loca.getLivre().getAuteur() + "\n");
- } else {
- System.out.println("LOCATION : " + loca.getId_location() + " DATE EMPRUNT : " + loca.getDate_emprunt() + " DATE RETOUR : " + loca.getDate_retour());
- System.out.println("CLIENT : " + loca.getClient().getNom() + " " + loca.getClient().getPrenom());
- System.out.println("LIVRE :\t\"" + loca.getLivre().getTitre().toUpperCase() + "\" de " + loca.getLivre().getAuteur() + "\n");
- }
- }
- break;
- case 4:
- Livre l = new Livre();
- System.out.println("Vous êtes sur le point d'ajouter un livre");
- System.out.println("Code barre ? (13 chiffres)");
- l.setCode_barre(In.readString());
- System.out.println("Titre ? ");
- l.setTitre(In.readString());
- System.out.println("Auteur ? ");
- l.setAuteur(In.readString());
- System.out.println("Genre ? ");
- l.setGenre(In.readString());
- System.out.println("Résumé ? ");
- l.setRésumé(In.readString());
- etat.executeUpdate("INSERT INTO livre (id_livre, titre, code_barre, auteur, genre, résumé) " + "VALUES (NULL, '" + l.getTitre() + "', '" + l.getCode_barre() + "', '" + l.getAuteur() + "', '" + l.getGenre() + "', '" + l.getRésumé() + "')");
- break;
- case 5:
- Client c = new Client();
- System.out.println("Vous êtes sur le point d'ajouter un client");
- System.out.println("Numéro client ?");
- c.setNumero_client(In.readInteger());
- System.out.println("Nom ?");
- c.setNom(In.readString());
- System.out.println("Prenom?");
- c.setPrenom(In.readString());
- System.out.println("Adresse");
- c.setAdresse(In.readString());
- System.out.println("Téléphone?");
- c.setTéléphone(In.readString());
- etat.executeUpdate("INSERT INTO client (id_client, numero_client, nom, prenom, adresse, téléphone) " + "VALUES (NULL, '" + c.getNumero_client() + "', '" + c.getNom() + "', '" + c.getPrenom() + "', '" + c.getAdresse() + "', '" + c.getTéléphone() + "')");
- case 6:
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement