As datas passei como Date tanto nas classes como no banco, segue o codigo da classe fCadastroProjetos, coloquei aqui só a parte mais importante(para essa dúvida) da classe.
public class FCadastroProjetos extends javax.swing.JDialog {
/** Creates new form FCadastroProjetos */
public FCadastroProjetos(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
carregaComboBoxResponsavel();
}
public void carregaComboBoxResponsavel(){
ResponsavelDAO dao = new ResponsavelDAO();
for (Responsavel responsavel : dao.listaTodos()) {
jComboBoxResponsavel.addItem(responsavel);
}
}
/** 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")
private void jButtonSalvarActionPerformed(java.awt.event.ActionEvent evt) {
try {
Projeto projeto = new Projeto();
ProjetoDAO dao = new ProjetoDAO();
String dataInicio = jTextFieldDataInicio.getText();
String dataFim = jTextFieldDataFim.getText();
Date novaDataInicio = new SimpleDateFormat("dd/MM/yyyy").parse(dataInicio);
Date novaDataFim = new SimpleDateFormat("dd/MM/yyyy").parse(dataFim);
projeto.setDataInicio(novaDataInicio);
projeto.setDataFim(novaDataFim);
projeto.setDescricao(jTextFieldDescricao.getText());
projeto.setResponsavel((Responsavel) jComboBoxResponsavel.getSelectedItem());
dao.salvar(projeto);
JOptionPane.showMessageDialog(this, "Projeto cadastrado com sucesso");
} catch (ParseException ex) {
Logger.getLogger(FCadastroProjetos.class.getName()).log(Level.SEVERE, null, ex);
}
}
Aqui segue como to salvando no DAO do Projeto
public class ProjetoDAO {
public void salvar(Projeto projeto) {
Connection con = null;
try {
String sql = "insert into tab_projeto(descricao, data_inicio, data_fim, id_responsavel) values(?, ?, ?, ?)";
con = ConnectionFactory.getConnection();
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1, projeto.getDescricao());
stmt.setDate(2, new java.sql.Date(projeto.getDataInicio().getTime()));
stmt.setDate(3, new java.sql.Date(projeto.getDataFim().getTime()));
stmt.setLong(4, projeto.getResponsavel().getId());
stmt.execute();
} catch (SQLException ex) {
Logger.getLogger(ProjetoDAO.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
con.close();
} catch (SQLException ex) {
Logger.getLogger(ProjetoDAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Também tenho um metodo de listar, mas esse é pra retornar tudo, só as datas n consegui.