Advertisement
Guest User

Untitled

a guest
Apr 21st, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Scanner;
  3.  
  4. public class Question5 {
  5. public static void main (String args[]) {
  6. try {
  7. Class.forName("oracle.jdbc.driver.OracleDriver");
  8. }
  9. catch (ClassNotFoundException e) {
  10. System.out.println("Impossible de chargé les pilotes");
  11. e.printStackTrace();
  12. System.exit(1);
  13. }
  14. System.out.println("Pilote chargé");
  15. String url = "jdbc:oracle:thin:SEPIARD/azerty91@oracle.iut-orsay.fr:1521:etudom";
  16. Connection maConnexion = null;
  17.  
  18. try {
  19. maConnexion = DriverManager.getConnection(url);
  20. }
  21. catch (SQLException e) {
  22. System.out.println("Impossible de se connecter à l'url : " + url);
  23. e.printStackTrace();
  24. System.exit(1);
  25. }
  26. System.out.println("Connection établie");
  27.  
  28. try {
  29. Scanner sc = new Scanner(System.in);
  30. int resultat, i;
  31. int returnVal = 0;
  32. String nomActeur, prenomActeur, nomFilm;
  33. int numActeur, numFilm;
  34.  
  35. System.out.println("Entrez le nom d'un acteur : ");
  36. nomActeur = sc.next();
  37.  
  38. //pst.setInt(1, nomActeur);
  39.  
  40. //maConnexion.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  41. //pst.execute();
  42. Statement monInstruction = maConnexion.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  43.  
  44. ResultSet monResultat = monInstruction.executeQuery("SELECT numIndividu, prenomIndividu, nomIndividu FROM ens2004.Individu WHERE nomIndividu = '" + nomActeur + "'");
  45. //ResultSetMetaData myMetaData = monResultat.getMetaData();
  46. //int nbCol = myMetaData.
  47.  
  48. //monResultat.
  49. i = 1;
  50.  
  51. while (monResultat.next()) {
  52. System.out.println(i + " " + monResultat.getString(2) + " " + monResultat.getString(3));
  53. i++;
  54. }
  55.  
  56. System.out.println("Votre choix : ");
  57. i = Integer.parseInt(sc.next());
  58.  
  59. monResultat.absolute(i);
  60. //monResultat.next();
  61.  
  62. prenomActeur = monResultat.getString("prenomIndividu");
  63. numActeur = monResultat.getInt("numIndividu");
  64.  
  65. System.out.println("Vous avez choisi : " + prenomActeur + " " + nomActeur);
  66. System.out.println("Il a joué dans : ");
  67.  
  68. monResultat = monInstruction.executeQuery("SELECT f.numFilm, titre FROM ens2004.Film f JOIN ens2004.Acteur a on f.numFilm = a.numFilm WHERE a.numIndividu = " + numActeur);
  69.  
  70. i = 1;
  71.  
  72. while (monResultat.next()) {
  73. System.out.println(i + " " + monResultat.getString(2));
  74. i++;
  75. }
  76.  
  77. System.out.println("Votre choix : ");
  78. i = Integer.parseInt(sc.next());
  79.  
  80. monResultat.absolute(i);
  81. nomFilm = monResultat.getString("titre");
  82. numFilm = monResultat.getInt("numFilm");
  83.  
  84. System.out.println("Vous avez choisi : " + nomFilm);
  85. System.out.println("Voici les exemplaires de ce film : ");
  86.  
  87. monResultat = monInstruction.executeQuery("SELECT numExemplaire FROM ens2004.Exemplaire WHERE numFilm = " + numFilm);
  88.  
  89. while (monResultat.next()) {
  90. System.out.println(monResultat.getString(1));
  91. }
  92. maConnexion.close();
  93. }
  94. catch (SQLException e) {
  95. e.printStackTrace();
  96. System.exit(1);
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement