I have a form in JSF and I need to insert the data of it into the database I have already researched in several ways, but it is not working
Could you give me a hand in what I'm doing wrong? JSF
Form
I am not able to pass the parameter of what is being entered for insertion into 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 + "]"; }
}