Advertisement
Guest User

to nicolas

a guest
Mar 13th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. import java.sql.SQLException;
  2. import java.util.Vector;
  3.  
  4. import javax.sql.rowset.JdbcRowSet;
  5. import javax.sql.rowset.RowSetProvider;
  6.  
  7. public class tourdumonde {
  8. JdbcRowSet rowSetMySQL;
  9. JdbcRowSet rowSetOracle;
  10.  
  11. static String ville1 = "Paris";
  12.  
  13. public void connectMySQL() throws SQLException {
  14. rowSetMySQL = RowSetProvider.newFactory().createJdbcRowSet();
  15. rowSetMySQL.setUrl("jdbc:mysql://localhost:3306/qc");
  16. rowSetMySQL.setUsername("root");
  17. rowSetMySQL.setPassword("toto");
  18.  
  19. }
  20.  
  21. public void connectOracle() throws SQLException {
  22. rowSetOracle = RowSetProvider.newFactory().createJdbcRowSet();
  23. rowSetOracle.setUrl("jdbc:oracle:thin:\"qcoloos\"/20051996@192.168.22.60:1521:orcl2");
  24.  
  25. }
  26.  
  27. public void afficheDestination(String ville) throws SQLException {
  28. JdbcRowSet rowSetOracle;
  29. rowSetOracle = RowSetProvider.newFactory().createJdbcRowSet();
  30. rowSetOracle.setUrl("jdbc:oracle:thin:\"qcoloos\"/20051996@192.168.22.60:1521:orcl2");
  31. rowSetOracle.setCommand("select * from vol where Ville_depart = ?");
  32. rowSetOracle.setString(1, ville);
  33. rowSetOracle.execute();
  34. JdbcRowSet rowSetMySQL;
  35. rowSetMySQL = RowSetProvider.newFactory().createJdbcRowSet();
  36. rowSetMySQL.setUrl("jdbc:mysql://localhost:3306/qc");
  37. rowSetMySQL.setUsername("root");
  38. rowSetMySQL.setPassword("toto");
  39. rowSetMySQL.setCommand("select * from Escales where Ville_escale = ?");
  40. rowSetMySQL.setString(1, ville);
  41. rowSetMySQL.execute();
  42. if(rowSetMySQL.next()){
  43. while (rowSetOracle.next() ) {
  44.  
  45.  
  46. System.out.println("---------------------------");
  47. ville1 = (rowSetOracle.getString("Ville_arrivee"));
  48. System.out.println("NumVol: " + rowSetOracle.getString("NumVol"));
  49. System.out.println("Ville_depart: " + rowSetOracle.getString("Ville_depart"));
  50. System.out.println("Ville_arrivee: " + rowSetOracle.getString("Ville_arrivee"));
  51. System.out.println("Durée escales a : "+rowSetMySQL.getString("Ville_escale") + " est de : " + rowSetMySQL.getString("Duree_escale_minimum"));
  52. if (!rowSetOracle.getString("Ville_arrivee").equals("Paris")) {
  53. afficheDestination(ville1);
  54. }
  55. }
  56. }else {
  57. while (rowSetOracle.next() ) {
  58.  
  59. System.out.println("---------------------------");
  60. ville1 = (rowSetOracle.getString("Ville_arrivee"));
  61. System.out.println("NumVol: " + rowSetOracle.getString("NumVol"));
  62. System.out.println("Ville_depart: " + rowSetOracle.getString("Ville_depart"));
  63. System.out.println("Ville_arrivee: " + rowSetOracle.getString("Ville_arrivee"));
  64. System.out.println("Pas d'Escale");
  65. if (!rowSetOracle.getString("Ville_arrivee").equals("Paris")) {
  66. afficheDestination(ville1);
  67. }
  68. }
  69. }
  70.  
  71. }
  72.  
  73. public static void main(String[] args) {
  74. // TODO Auto-generated method stub
  75. try {
  76. tourdumonde bdd = new tourdumonde();
  77. bdd.connectMySQL();
  78. bdd.connectOracle();
  79. System.out.println("*Tour du monde Paris*");
  80. bdd.afficheDestination(ville1);
  81.  
  82. } catch (SQLException e) {
  83. // TODO Auto-generated catch block
  84. e.printStackTrace();
  85. }
  86.  
  87. }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement