Beispiel #1
0
 public static void save(Jugador jugador) {
   PreparedStatement stmt = null;
   ResultSet rs = null;
   try {
     stmt =
         ConexionDB.getInstancia()
             .getConexion()
             .prepareStatement(
                 "insert into jugadores(dni, nombre, apellido) values (?,?,?)",
                 PreparedStatement.RETURN_GENERATED_KEYS);
     stmt.setInt(1, jugador.getDni());
     stmt.setString(2, jugador.getNombre());
     stmt.setString(3, jugador.getApellido());
     stmt.execute();
     rs = stmt.getGeneratedKeys();
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     try {
       if (rs != null) rs.close();
       if (stmt != null) stmt.cancel();
     } catch (SQLException e) {
       e.printStackTrace();
     }
     ConexionDB.getInstancia().releaseConexion();
   }
 }
 private void testCancelReuse(Connection conn) throws Exception {
   conn.createStatement().execute("CREATE ALIAS SLEEP FOR \"java.lang.Thread.sleep\"");
   // sleep for 10 seconds
   final PreparedStatement prep =
       conn.prepareStatement("SELECT SLEEP(?) FROM SYSTEM_RANGE(1, 10000) LIMIT ?");
   prep.setInt(1, 1);
   prep.setInt(2, 10000);
   Task t =
       new Task() {
         @Override
         public void call() throws SQLException {
           prep.execute();
         }
       };
   t.execute();
   Thread.sleep(100);
   prep.cancel();
   SQLException e = (SQLException) t.getException();
   assertTrue(e != null);
   assertEquals(ErrorCode.STATEMENT_WAS_CANCELED, e.getErrorCode());
   prep.setInt(1, 1);
   prep.setInt(2, 1);
   ResultSet rs = prep.executeQuery();
   assertTrue(rs.next());
   assertEquals(0, rs.getInt(1));
   assertFalse(rs.next());
 }
Beispiel #3
0
 public static Jugador getByDni(int dni) {
   Jugador jugador = null;
   PreparedStatement stmt = null;
   ResultSet rs = null;
   try {
     stmt =
         ConexionDB.getInstancia()
             .getConexion()
             .prepareStatement("select dni, nombre, apellido from jugadores where dni = ?");
     stmt.setInt(1, dni);
     rs = stmt.executeQuery();
     if (rs != null && rs.next()) {
       jugador = new Jugador(rs.getInt("dni"), rs.getString("nombre"), rs.getString("apellido"));
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     try {
       if (rs != null) rs.close();
       if (stmt != null) stmt.cancel();
     } catch (SQLException e) {
       e.printStackTrace();
     }
     ConexionDB.getInstancia().releaseConexion();
   }
   return jugador;
 }
  public void cancel() throws SQLException {
    Profiler profiler = _profilerPoint.start();

    try {
      _preparedStatement.cancel();
    } finally {
      profiler.finish();
    }
  }
Beispiel #5
0
 @Override
 public final void cancel() {
   if (statement != null) {
     try {
       statement.cancel();
     } catch (SQLException e) {
       throw Tools.translate(rendered.sql, e);
     }
   }
 }
 @Override
 public void cancel() {
   super.cancel();
   if (retrievalStatement != null) {
     try {
       retrievalStatement.cancel();
     } catch (Exception sql) {
       // nothing to do
     }
   }
 }
Beispiel #7
0
 @Override
 public void cancel() throws JdbcException {
   try {
     if (preparedStatement != null && !preparedStatement.isClosed()) {
       preparedStatement.cancel();
     }
   } catch (SQLException ex) {
     throw newJdbcException(ex);
   }
   try {
     if (callableStatement != null && !callableStatement.isClosed()) {
       callableStatement.cancel();
     }
   } catch (SQLException ex) {
     throw newJdbcException(ex);
   }
 }
 public void cancel() throws SQLException {
   if (ps != null) {
     ps.cancel();
   }
 }
 public void cancel() throws SQLException {
   statement.cancel();
 }
 public void cancel() throws SQLException {
   delegate.cancel();
 }
 @Override
 public void cancel() throws SQLException {
   stmt.cancel();
 }