Advertisement
moreiramota

Untitled

Dec 22nd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. public Journey getJourney(int idReservation) {
  2. CallableStatement callStmt = null;
  3. /* Objeto "callStmt" para invocar a função "getBicycle" armazenada na BD.
  4. *
  5. * FUNCTION getBicycle(id NUMBER) RETURN pkgBicycle.ref_cursor
  6. * PACKAGE pkgSailors AS TYPE ref_cursor IS REF CURSOR; END pkgSailors;
  7. */
  8. try {
  9. callStmt = getConnection().prepareCall("{ ? = call getReservationHistory(?) }");
  10.  
  11. // Regista o tipo de dados SQL para interpretar o resultado obtido.
  12. callStmt.registerOutParameter(1, OracleTypes.CURSOR);
  13.  
  14. // Especifica o parâmetro de entrada da função "getReservationHistory".
  15. callStmt.setInt(2, idReservation);
  16.  
  17. // Executa a invocação da função "getBycycle()".
  18. callStmt.execute();
  19.  
  20. // Guarda o cursor retornado num objeto "ResultSet".
  21. ResultSet rSet = (ResultSet) callStmt.getObject(1);
  22. if (rSet.next()) {
  23. Journey journey = createJourney(rSet);
  24.  
  25. rSet.close();
  26.  
  27. callStmt = getConnection().prepareCall("{ ? = call getAllRouteByReservation(?) }");
  28.  
  29. callStmt.registerOutParameter(1, OracleTypes.CURSOR);
  30. callStmt.setInt(2, idReservation);
  31.  
  32. callStmt.execute();
  33. rSet = (ResultSet) callStmt.getObject(1);
  34. while (rSet.next()) {
  35. journey.addRoute(RouteDB.createRoute(rSet));
  36. }
  37. closeAll();
  38. return journey;
  39. }
  40.  
  41. } catch (SQLException e) {
  42. e.printStackTrace();
  43. }
  44. throw new IllegalArgumentException("No Journey with id:" + idReservation);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement