コード例 #1
0
  @Override
  public boolean insert(StudentEntity entity) {
    boolean isInsert = false;

    try {
      PreparedStatement statement =
          connection.prepareStatement("INSERT INTO StudentEntity(name, surname) VALUES (?, ?)");

      statement.setString(1, entity.getName());
      statement.setString(2, entity.getSurname());
      int result = statement.executeUpdate();
      statement.close();
      isInsert = true;
    } catch (SQLException e) {
      System.out.println("Не вірний SQL запит на вставку");
      e.printStackTrace();
    }

    return isInsert;
  }
コード例 #2
0
  @Override
  public boolean update(StudentEntity entity) {
    boolean isUpdated = false;

    try {
      PreparedStatement statement =
          connection.prepareStatement(
              "UPDATE StudentEntity SET name = ?, surname = ? WHERE id = ?");

      statement.setString(1, entity.getName());
      statement.setString(2, entity.getSurname());
      statement.setInt(3, entity.getId_student());

      int result = statement.executeUpdate();
      statement.close();
      isUpdated = true;
    } catch (SQLException e) {
      System.out.println("Не вірний SQL запит на видалення");
      e.printStackTrace();
    }

    return isUpdated;
  }