Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Journey getJourney(int idReservation) {
- CallableStatement callStmt = null;
- /* Objeto "callStmt" para invocar a função "getBicycle" armazenada na BD.
- *
- * FUNCTION getBicycle(id NUMBER) RETURN pkgBicycle.ref_cursor
- * PACKAGE pkgSailors AS TYPE ref_cursor IS REF CURSOR; END pkgSailors;
- */
- try {
- callStmt = getConnection().prepareCall("{ ? = call getReservationHistory(?) }");
- // Regista o tipo de dados SQL para interpretar o resultado obtido.
- callStmt.registerOutParameter(1, OracleTypes.CURSOR);
- // Especifica o parâmetro de entrada da função "getReservationHistory".
- callStmt.setInt(2, idReservation);
- // Executa a invocação da função "getBycycle()".
- callStmt.execute();
- // Guarda o cursor retornado num objeto "ResultSet".
- ResultSet rSet = (ResultSet) callStmt.getObject(1);
- if (rSet.next()) {
- Journey journey = createJourney(rSet);
- rSet.close();
- callStmt = getConnection().prepareCall("{ ? = call getAllRouteByReservation(?) }");
- callStmt.registerOutParameter(1, OracleTypes.CURSOR);
- callStmt.setInt(2, idReservation);
- callStmt.execute();
- rSet = (ResultSet) callStmt.getObject(1);
- while (rSet.next()) {
- journey.addRoute(RouteDB.createRoute(rSet));
- }
- closeAll();
- return journey;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- throw new IllegalArgumentException("No Journey with id:" + idReservation);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement