JDateChooser fulfill with date by selected item from JComboBox which is connected from database Sqlite

35 Views Asked by At

Can someone help me? I want JDateChooserdateChooserBrithIDCard to fill with date based on the selected item in a JComboBox which is connected to a SQLite database. The code shows an option for JTextField, which works perfectly, like for example:

txtnameIDCard.setText(rs.getString("Firstname"));

While I used the following code:

dateChooserBrithIDCard.setDate(rs.getDate("DateOfBrith"));

for JDateChooser but it doesn't work. It shows me the following error:

java.sql.SQLException: Error parsing time stamp

Can anyone advise me the right code how to make this thing work?

comboBoxIDNumberIDCard = new JComboBox();
comboBoxIDNumberIDCard.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        try {
            String sql ="select * from employee where EmployeeID=?";
            PreparedStatement pst = conn.prepareStatement(sql);
            pst.setString(1, (String)comboBoxIDNumberIDCard.getSelectedItem());
            ResultSet rs=pst.executeQuery();
            while(rs.next()){
                txtnameIDCard.setText(rs.getString("Firstname"));//working
                txtIDSurname.setText(rs.getString("Surname"));//working
                dateChooserBrithIDCard.setDate(rs.getDate("DateOfBrith"));
                //This one not working, not showing any date of Brith From Database SQLITE                     
            } 
        }catch (Exception e1) {
            e1.printStackTrace();
        }
    }
});

I would be grateful for the right code, to make things working perfectly with JDateChooser.

enter image description here

0

There are 0 best solutions below