Estou querendo inserir dados na tabela que criei… mas não está inserindo…
O que deve estar errado ou faltando no codigo abaixo:
Atenciosamente,
Diego
<%@ page language="java"
contentType="text/html;"
pageEncoding="ISO-8859-1"
import="java.sql.*"
%>
<%
String matricula = request.getParameter("matricula");
String nome = request.getParameter("nome");
Connection conn = null;
PreparedStatement pst = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/db",
"diego","planet");
String SQL = "INSERT INTO aluno (matricula, nome) values (?,?)";
pst = conn.prepareStatement(SQL);
pst.setInt(1, Integer.parseInt(matricula));
pst.setString(2, nome);
pst.executeUpdate(SQL);
pst.clearParameters();
}catch (Exception ex) {
ex.printStackTrace();
}finally {
if (pst != null) pst.close();
if (pst != null) conn.close();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Dados recebidos</title>
</head>
<body>
O Matrícula: <strong><%=matricula %></strong> foi inserido com sucesso!
Clique no Link para Exibir os dados:
<a href='ExibirDados.jsp'>Exibir Dados</a>
</body>
</html>