I would strongly urge you to help me solve a Date (SQL) data insertion problem for new student enrollment in the Crud project developed by me in the code below. The method containing the INSERT INTO command does not insert a new record in the database because the text typed in the dd / MM / yyyy format obtained in Jtextfield is not accepted as a Date format data in SQL.
package grafico;
import static com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type.String;
import java.sql.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import sistema.Conectora;
public class Tela extends javax.swing.JFrame {
Connection c = null;
PreparedStatement ps = null;
ResultSet rs = null;
public Tela() {
initComponents();
setLocationRelativeTo(null);
c = Conectora.conectora();
}
public void cadastrar() throws ParseException{
String consulta = "INSERT INTO alunos (aluno, , nascimento, mae, pai, sexo, serie) VALUES (?,?,?,?,?,?);";
try {
ps = c.prepareStatement(consulta);
ps.setString(1,campoAluno.getText());
ps.setDate(2, new Date(campoNascimento.getText()));
ps.setString(3,campoMae.getText());
ps.setString(4,campoPai.getText());
ps.setString(5,campoSexo.getText());
ps.setInt(6,(Integer.parseInt(campoSerie.getText())));
ps.execute();
JOptionPane.showMessageDialog(null,"Cadastrado com sucesso!");
}catch(SQLException e){
JOptionPane.showMessageDialog(null, e);
}
}