Boa tarde pessoal, depois de muito tentar tentar e tentar venho aqui ver se alguém consegue me ajudar, tenho que criar uma conexão com o banco e fazer um insert mas infelizmente não estou conseguindo e o netbeans não retorna nenhum um erro que faça eu saber onde está o problema. Segue o trecho dos códigos.
JSP
<html>
<head></head>
<body>
<form id="form-teste" action="Cadastro" method="POST">
<label class="fontes">Nome</label></td> <td><input type="text" class="" name="nome">
<input type="submit">
</body>
</html>
Servlet - Vou postar resumidamente pois debugando vi que os parâmetros estão sendo capturados por ela.
String nome = request.getParameter("nome");
Cliente cliente = new Cliente();
cliente.setNome(nome);
ClienteDAO clieDao = new ClienteDAO();
clieDao.inserir(cliente);
Classe Cliente
public class Cliente {
private String nome;
public Cliente() {
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}
ClienteDAO
public class ClienteDAO {
private Connection connection;
private PreparedStatement stmtInsere;
public ClienteDAO() throws SQLException {
this.connection = new ConnectionFactory().getConnection();
stmtInsere = (PreparedStatement) connection.prepareStatement
("INSERT INTO C001(C001_Nome_Cliente) VALUES ('?'))");
}
public void inserir(Cliente cliente) throws Exception {
stmtInsere.setString(1, cliente.getNome());
stmtInsere.execute();
}
}
Classe Connection
public class ConnectionFactory {
public Connection getConnection() {
try {
return DriverManager.getConnection("jdbc:mysql://localhost/lavanderia", "root", "");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
Quando rodo no navegador ele abre a página, digito no campo e dou submit ele é redirecionado, e não me retorna nenhum erro e não insere, o driver do mysql já está configurando no netbeans, estou usando o mysql que vem no wamp.