Esempio n. 1
0
  public static void update(Dia dia) {
    Connector.connect();
    Connector.update(
        "UPDATE dia SET iddia = " + dia.getIdDia() + ", data ='" + dia.getData() + "';");

    Connector.close();
  }
Esempio n. 2
0
  /**
   * Performs a DELETE SQL statement on the database.
   *
   * @param sql as String. It is the insert query.
   * @param values as Object array.
   * @return int rowsAffected whose value is number of rows affected or 0 when statement does not
   *     return anything.
   */
  public static int delete(String sql, Object[] values) {
    init();

    try {
      preparedStatement = connection.prepareStatement(sql);
    } catch (SQLException e) {
      Reporter.error(e);
    }

    for (int i = 1; i <= values.length; i++) {
      try {
        preparedStatement.setObject(i, values[i - 1]);
      } catch (SQLException e) {
        Reporter.error(e);
      }
    }

    try {
      rowsAffected = preparedStatement.executeUpdate();
    } catch (SQLException e) {
      Reporter.error(e);
    }

    Connector.close(resultSet, preparedStatement, connection);

    return rowsAffected;
  }
Esempio n. 3
0
  public static void create(Dia dia) {

    Connector.connect();
    Connector.update("INSERT INTO dia (data)" + " VALUES ('" + dia.getData() + "'); ");

    Connector.close();
  }
 public void destroy() {
   try {
     if (connection != null) {
       connection.close();
     }
   } catch (Exception e) {
   }
 }
Esempio n. 5
0
 public static Dia read(Date data) {
   Dia dia = null;
   Connector.connect();
   ResultSet resultSet = Connector.query("SELECT * FROM dia WHERE data ='" + data + "';");
   try {
     if (resultSet.next()) {
       dia = new Dia();
       dia.setIdDia(resultSet.getLong("iddia"));
       dia.setData(resultSet.getDate("data"));
     }
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
   Connector.close();
   return dia;
 }
Esempio n. 6
0
  /**
   * Executes a generic statement on the database.
   *
   * <h5>Note :</h5>
   *
   * It is not a prepared statement.
   *
   * @param sql as String
   */
  public static void statement(String sql) {
    init();

    try {
      statement = connection.createStatement();
    } catch (SQLException e) {
      Reporter.error(e);
    }

    try {
      statement.executeUpdate(sql);
    } catch (SQLException e) {
      Reporter.error(e);
    }

    Connector.close(resultSet, preparedStatement, connection);
  }
Esempio n. 7
0
 public static ArrayList<Dia> getAll() {
   ArrayList<Dia> lista = new ArrayList<Dia>();
   Dia dia = null;
   Connector.connect();
   ResultSet resultSet = Connector.query("SELECT * FROM dia;");
   try {
     while (resultSet.next()) {
       dia = new Dia();
       dia.setIdDia(resultSet.getLong("iddia"));
       dia.setData(resultSet.getDate("data"));
       lista.add(dia);
     }
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
   Connector.close();
   return lista;
 }
Esempio n. 8
0
 /**
  * Closes the database connection. It is a good practice to close the database connection when it
  * is not in use.
  */
 public static void close() {
   Connector.close(resultSet, preparedStatement, connection);
 }
Esempio n. 9
0
 public static void delete(long idDia) {
   Connector.connect();
   Connector.update("DELETE FROM dia WHERE iddia=" + idDia + ";");
   Connector.close();
 }