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.