示例#1
0
  // to implement
  public void add(Funcionario funcionario) {
    String sql =
        "INSERT INTO Funcionario (nome_funcionario, especialidade, comissao) VALUES (?, ?, ?)";
    // String sqlNumFunc = "SELECT id_funcionario FROM Funcionario WHERE nome_funcionario = '?'";

    try {
      PreparedStatement stmt = (PreparedStatement) connection.prepareStatement(sql);

      stmt.setString(1, funcionario.getNomeFuncionario());
      stmt.setString(2, funcionario.getEspecialidade());
      stmt.setDouble(3, funcionario.getComissao());

      stmt.execute();

      // stmt = (PreparedStatement) connection.prepareStatement(sqlNumFunc);
      // stmt.execute();

      // ResultSet rs = stmt.executeQuery();
      // funcionario.setNumFuncionario(rs.);

      stmt.close();

      System.out.println("Funcionario Inserted Successfully");
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
示例#2
0
  public void remove(Funcionario funcionario) {
    String sql = "DELETE FROM Funcionario WHERE id_funcionario = '?'";
    // String sql = "DELETE FROM Funcionario WHERE nome_funcionario = ?";

    try {
      PreparedStatement stmt = (PreparedStatement) connection.prepareStatement(sql);

      stmt.setString(1, funcionario.getNomeFuncionario());

      stmt.execute();
      stmt.close();

      System.out.println(
          "Funcionario: " + funcionario.getNomeFuncionario() + " deleted successfully");
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }