stmt.setDouble(2, vo.getTarifaDiurna());
stmt.setDouble(3, vo.getTarifaNocturna());
stmt.setInt(4, vo.getLocal().getId());
int i = stmt.executeUpdate();
if (i != 1) {
throw new BaseExcepcion("Error al insertar cancha");
}
keys = stmt.getGeneratedKeys();
keys.next();
idCancha = keys.getInt(1);
vo.setId(idCancha);
} catch (SQLException e) {
System.err.println(e.getMessage());
throw new BaseExcepcion(e.getMessage());
} finally {
this.cerrarResultSet(keys);
this.cerrarStatement(stmt);
}
//Insertar horario
query = "INSERT INTO tb_horariocancha(dia, hora,idCancha) VALUES (?,?,?)";
for (HorarioCancha hc : lista) {
try {
stmt = con.prepareStatement(query);
stmt.setString(1, hc.getDia());
stmt.setString(2, hc.getHora());
stmt.setInt(3, idCancha);
int i = stmt.executeUpdate();
if (i != 1) {
throw new BaseExcepcion("Error al insertar horario");
}
} catch (SQLException e) {
System.err.println(e.getMessage());
throw new BaseExcepcion(e.getMessage());
} finally {
this.cerrarStatement(stmt);
}
}