0
I have a form in JSF and I need to enter his data in the database I’ve searched several ways, but it’s not working
Could you give me a hand with what I’m doing wrong? JSF
Form
I am not able to pass the parameter of what is being typed for insertion in the database:
@ManagedBean(name="UsuarioJDCBDAO")
public void inserir(Usuario usuario) {
try {
Connection conexao = getConexao();
String value = null; Statement stmt = null; conexao.createStatement().execute("SET IDENTITY_INSERT "+"tbplan"+" ON"); stmt = conexao.createStatement(); ResultSet rs = stmt.executeQuery("select MAX(id) + 1 from tbplan");
while (rs.next()) value = rs.getString(1).toString();
System.out.println(value);
PreparedStatement pstm = conexao .prepareStatement("Insert into tbplan (data, nome, frase, id) values (?,?,?,?)");
//String name = new Usuario().getNome(); //pstm.setDate(1, new java.sql.Date(usuario.getDataCadastro().getTime())); pstm.setString(1, "26 Jun 2017 14:28:00:00");
pstm.setString(2, usuario.getNome());
// pstm.setString(2, n1.getNome()); pstm.setString(3, usuario.getFrase()); pstm.setString(4, value);
pstm.execute(); conexao.createStatement().execute("SET IDENTITY_INSERT "+"tbplan"+" OFF"); pstm.close(); conexao.close(); } catch (Exception e) { e.printStackTrace(); }
}
User-class
import java.io.Serializable; import java.util.Date;
public class Usuario implements Serializable {
private static final long serialVersionUID = -309513637403441998L;
private Long id;
private Date dataCadastro;
private String nome;
private String frase;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public Date getDataCadastro() { return dataCadastro; }
public void setDataCadastro(Date dataCadastro) { this.dataCadastro = dataCadastro; }
public String getNome() { return nome; }
public void setNome(String nome) { this.nome = nome; }
public String getFrase() { return frase; }
public void setFrase(String frase) { this.frase = frase; }
@Override public String toString() { return "Usuario [nome=" + nome + ", frase=" + frase + ", dataCadastro=" + dataCadastro + " id=" + id + "]"; }
}
You can receive this parameter in your Managedbean?
– DiegoAugusto
I put a println and could not list it
– user82889
apparently the problem lies precisely in this passage from jsf to bean
– user82889
You can edit your question by clicking the edit button just below the tags, then you add the code of the page where Voce is trying to pass the values
– DiegoAugusto
That one answer will help you. If you do not understand, getting home put an answer here
– igventurelli