Advertisement
Guest User

theophane lpb

a guest
Dec 22nd, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package fr.btssnir;
  7.  
  8. import clavier.In;
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13. import java.sql.Statement;
  14. import java.util.ArrayList;
  15.  
  16. /**
  17. *
  18. * @author bbrancourt
  19. */
  20. public class BRANCOURT_Bastien_TP_Biblio {
  21.  
  22. /**
  23. * @param args the command line arguments
  24. */
  25. public static void main(String[] args) throws ClassNotFoundException, SQLException {
  26.  
  27. int menu;
  28. ArrayList<Livre> listLivre = new ArrayList();
  29. ArrayList<Client> listClient = new ArrayList();
  30. ArrayList<Location> listLocation = new ArrayList();
  31. Class.forName("com.mysql.jdbc.Driver");
  32. Connection connexion = DriverManager.getConnection("jdbc:mysql://localhost/bibliothèque", "root", "");
  33. Statement etat = connexion.createStatement();
  34. ResultSet rs = null;
  35.  
  36. 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");
  37. menu = In.readInteger();
  38. switch (menu) {
  39.  
  40. case 1:
  41. rs = etat.executeQuery("SELECT * from livre");
  42. while (rs.next()) {
  43. 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é"));
  44. listLivre.add(l);
  45. }
  46. for (Livre li : listLivre) {
  47. System.out.println("\nCODE BARRE : " + li.getCode_barre() + "\nAUTEUR : " + li.getAuteur() + "\nTITRE : " + li.getTitre() + "\nGENRE : " + li.getGenre() + "\nRESUME : " + li.getRésumé());
  48. }
  49. break;
  50. case 2:
  51. rs = etat.executeQuery("SELECT * from client");
  52. while (rs.next()) {
  53. 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"));
  54. listClient.add(c);
  55. }
  56.  
  57. for (Client cl : listClient) {
  58. System.out.println("\nNUMERO CLIENT : " + cl.getNumero_client() + "\n\nNOM : " + cl.getNom() + "\nPRENOM : " + cl.getPrenom() + "\nADRESSE : " + cl.getAdresse() + "\nTELEPHONE : " + cl.getTéléphone());
  59.  
  60. }
  61. break;
  62. case 3:
  63. 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");
  64. while (rs.next()) {
  65. 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é"));
  66. 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"));
  67. Location loc = new Location(rs.getInt("id_location"), c, l, rs.getDate("date_emprunt"), rs.getDate("date_retour"));
  68. listLocation.add(loc);
  69. }
  70.  
  71. for (Location loca : listLocation) {
  72. if (loca.getDate_retour() == null) {
  73. System.out.println("LOCATION : " + loca.getId_location() + " DATE EMPRUNT : " + loca.getDate_emprunt() + " DATE RETOUR : ????");
  74. System.out.println("CLIENT : " + loca.getClient().getNom() + " " + loca.getClient().getPrenom());
  75. System.out.println("LIVRE :\t\"" + loca.getLivre().getTitre().toUpperCase() + "\" de " + loca.getLivre().getAuteur() + "\n");
  76. } else {
  77. System.out.println("LOCATION : " + loca.getId_location() + " DATE EMPRUNT : " + loca.getDate_emprunt() + " DATE RETOUR : " + loca.getDate_retour());
  78. System.out.println("CLIENT : " + loca.getClient().getNom() + " " + loca.getClient().getPrenom());
  79. System.out.println("LIVRE :\t\"" + loca.getLivre().getTitre().toUpperCase() + "\" de " + loca.getLivre().getAuteur() + "\n");
  80. }
  81. }
  82. break;
  83. case 4:
  84. Livre l = new Livre();
  85. System.out.println("Vous êtes sur le point d'ajouter un livre");
  86. System.out.println("Code barre ? (13 chiffres)");
  87.  
  88. l.setCode_barre(In.readString());
  89. System.out.println("Titre ? ");
  90. l.setTitre(In.readString());
  91. System.out.println("Auteur ? ");
  92. l.setAuteur(In.readString());
  93. System.out.println("Genre ? ");
  94. l.setGenre(In.readString());
  95. System.out.println("Résumé ? ");
  96. l.setRésumé(In.readString());
  97.  
  98. 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é() + "')");
  99. break;
  100.  
  101. case 5:
  102. Client c = new Client();
  103. System.out.println("Vous êtes sur le point d'ajouter un client");
  104. System.out.println("Numéro client ?");
  105. c.setNumero_client(In.readInteger());
  106. System.out.println("Nom ?");
  107. c.setNom(In.readString());
  108. System.out.println("Prenom?");
  109. c.setPrenom(In.readString());
  110. System.out.println("Adresse");
  111. c.setAdresse(In.readString());
  112. System.out.println("Téléphone?");
  113. c.setTéléphone(In.readString());
  114.  
  115. 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() + "')");
  116. case 6:
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement