How to make the student's registration number of the logged in account stay in the publication table made?

3

I'm doing a rating project for a "college", I have the publishing class and in it the method:

public String NovaPublicacao(Connection conn){

      String sqlInserir = "INSERT INTO Publicacao (Assunto, Conteudo, RA) VALUES (?, ?, (SELECT RA from Alunos where Nome = " + aluno.getNome() + "))";

      try (PreparedStatement stm = conn.prepareStatement(sqlInserir);) {
            stm.setString(1, getAssunto());
            stm.setString(2, getConteudo());
            stm.execute();
        } catch (Exception e) {
            e.printStackTrace();
            try {
                conn.rollback();
            } catch (SQLException e1) {
                System.out.print(e1.getStackTrace());
            }
        }

      return getConteudo().toString();
    }

How to make RA of the student logged, who made the publication, go to the publication table that has 1: n relation with the student, ie a student makes several publications.

    
asked by anonymous 17.11.2016 / 01:21

1 answer

0

I do not know if I understood your question well, but what you need is to simply remove this select from your insert code and add one more line:

stm.setString(1, getAssunto());
stm.setString(2, getConteudo());
stm.setString(3, getRA());
stm.execute();

When the student logs in you enter the RA of the same with a setRA (ra).

    
13.01.2017 / 12:20