3
I am doing a rating project of a "college", I have the publication 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 do AR of the student logged in, who made the publication, go to the publication table that has a relation of 1:n with the student, that is, a student makes several publications.
When the user logs in do you store the data in session? If so, just take the RA that is in the session. If the AR is not, add this information when the student logs in.
– Marcelo Gomes
student.Setra(Integer.parseint(txtRa.gettext()); student.setName(txtNome2.gettext()); student.setNome_user(txtLogin2.gettext()); student.setSenha(txtSenha2.gettext()); this would store the data in session?
– Vinicius Maciel
No! In this case you’re just populating the object, is Vc using JSF? If it’s JSF it would be like this instantiating a Session
SessionContext session = SessionContext.getInstance();
storing the data in a session =session.setAttribute("nomeUsuario", u.getNomeUsuario());
- Retrieving an attribute from SessionString nome = (String) session.getAttribute('nomeUsuario);
.– Marcelo Gomes
No, the interface was done manually, not using framework :(
– Vinicius Maciel
No problem. Search over Session and look for the implementation that fits your architecture.
– Marcelo Gomes