Preciso cadastrar os dados que o usuário coloca na tela cadastro e salva-lo no banco de dados, porém da erro quando clico em salvar. Segue abaixo o código da tela cadastro.
package view;
import factory.UsuarioDAO;
import javax.swing.JOptionPane;
import modelo.Usuario;
/**
*
* @author carlos.coutinho
*/
public class TelaCadastro extends javax.swing.JFrame {
/**
* Creates new form TelaCadastro
*/
public TelaCadastro() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
txtNome = new javax.swing.JTextField();
txtEmail = new javax.swing.JTextField();
jPSenha = new javax.swing.JPasswordField();
txtDataNasc = new javax.swing.JFormattedTextField();
txtCpf = new javax.swing.JFormattedTextField();
jLabel7 = new javax.swing.JLabel();
jBLimpar = new javax.swing.JButton();
jRMasculino = new javax.swing.JRadioButton();
jRFeminino = new javax.swing.JRadioButton();
jBCadastrar = new javax.swing.JButton();
jBRetornar = new javax.swing.JButton();
jLabel8 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(500, 441));
setResizable(false);
getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("NOME:");
getContentPane().add(jLabel1);
jLabel1.setBounds(40, 80, 34, 14);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("DATA NASCIMENTO:");
getContentPane().add(jLabel2);
jLabel2.setBounds(40, 110, 110, 30);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("E-MAIL:");
getContentPane().add(jLabel3);
jLabel3.setBounds(40, 150, 43, 30);
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("CPF:");
getContentPane().add(jLabel4);
jLabel4.setBounds(40, 190, 30, 20);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setText("SEXO:");
getContentPane().add(jLabel5);
jLabel5.setBounds(40, 230, 40, 20);
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("SENHA:");
getContentPane().add(jLabel6);
jLabel6.setBounds(40, 260, 40, 30);
txtNome.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtNomeActionPerformed(evt);
}
});
getContentPane().add(txtNome);
txtNome.setBounds(100, 70, 370, 30);
getContentPane().add(txtEmail);
txtEmail.setBounds(100, 150, 365, 30);
getContentPane().add(jPSenha);
jPSenha.setBounds(100, 260, 360, 30);
try {
txtDataNasc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
txtDataNasc.setDragEnabled(true);
txtDataNasc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtDataNascActionPerformed(evt);
}
});
getContentPane().add(txtDataNasc);
txtDataNasc.setBounds(170, 110, 299, 30);
try {
txtCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
getContentPane().add(txtCpf);
txtCpf.setBounds(100, 190, 365, 30);
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 255, 255));
jLabel7.setText("CADASTRO");
getContentPane().add(jLabel7);
jLabel7.setBounds(110, 0, 265, 58);
jBLimpar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jBLimpar.setText("LIMPAR");
jBLimpar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBLimparActionPerformed(evt);
}
});
getContentPane().add(jBLimpar);
jBLimpar.setBounds(100, 310, 120, 50);
jRMasculino.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jRMasculino.setForeground(new java.awt.Color(255, 255, 255));
jRMasculino.setText("MASCULINO");
getContentPane().add(jRMasculino);
jRMasculino.setBounds(100, 230, 100, 23);
jRFeminino.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jRFeminino.setForeground(new java.awt.Color(255, 255, 255));
jRFeminino.setText("FEMININO");
getContentPane().add(jRFeminino);
jRFeminino.setBounds(230, 230, 90, 23);
jBCadastrar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jBCadastrar.setText("CADASTRAR");
jBCadastrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBCadastrarActionPerformed(evt);
}
});
getContentPane().add(jBCadastrar);
jBCadastrar.setBounds(280, 310, 110, 50);
jBRetornar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jBRetornar.setText("RETORNAR");
jBRetornar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBRetornarActionPerformed(evt);
}
});
getContentPane().add(jBRetornar);
jBRetornar.setBounds(367, 380, 110, 23);
jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/Papel-de-Parede-fundo-azul-petroleo-com-mosaicos-35673.jpg"))); // NOI18N
jLabel8.setText("jLabel8");
getContentPane().add(jLabel8);
jLabel8.setBounds(0, 0, 500, 440);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void jBLimparActionPerformed(java.awt.event.ActionEvent evt) {
txtNome.setText("");
txtDataNasc.setText("");
txtEmail.setText("");
txtCpf.setText("");
jRMasculino.setText("");
jRFeminino.setText("");
jPSenha.setText("");
}
private void jBCadastrarActionPerformed(java.awt.event.ActionEvent evt) {
Usuario usuarios = new Usuario();
usuarios.setNome(txtNome.getText());
usuarios.setDtNascimento(txtDataNasc.getText());
usuarios.seteMail(txtEmail.getText());
usuarios.setCpf(txtCpf.getText());
usuarios.setSexo(jRMasculino.getText());
usuarios.setSexo(jRFeminino.getText());
usuarios.setSenha(jPSenha.getText());
if((txtNome.getText().isEmpty()) || (txtDataNasc.getText().isEmpty())|| (txtEmail.getText().isEmpty())|| (txtCpf.getText().isEmpty())||(jRMasculino.getText().isEmpty())||(jRFeminino.getText().isEmpty())||(jPSenha.getText().isEmpty())){
JOptionPane.showMessageDialog(null, "CAMPOS VAZIO, FAVOR PREENCHE-LOS PARA CONTINUAR","ERRO.!!",JOptionPane.ERROR_MESSAGE);
}
else{
this.hide();
TelaInicial t = new TelaInicial();
t.setVisible(true);
UsuarioDAO u = new UsuarioDAO();
Usuario user = new Usuario(txtNome.getText(),txtDataNasc.getText(), txtEmail.getText(),txtCpf.getText(),jPSenha.getText());
u.insert(user);
}
JOptionPane.showMessageDialog(this, "Cadastrado com sucesso!!!");
}
private void txtDataNascActionPerformed(java.awt.event.ActionEvent evt) {
}
private void txtNomeActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jBRetornarActionPerformed(java.awt.event.ActionEvent evt) {
TelaInicial ti = new TelaInicial();
ti.setVisible(true);
this.pack();
dispose();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TelaCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TelaCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TelaCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TelaCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TelaCadastro().setVisible(true);
}
});
}