0

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

Abra
  • 19,142
  • 7
  • 29
  • 41
SonyGame
  • 1
  • 1
  • Are you referring to this [JDateChooser](https://sourceforge.net/projects/jdatechooser/)? – Abra Nov 25 '22 at 15:45
  • Consider posting a [mcve]. What are the names of the columns and their data types in [database] table `employee`? If an [exception](https://docs.oracle.com/javase/tutorial/essential/exceptions/index.html) occurs, your code will print a stack trace. Since you have a GUI application, you may not have noticed if there is a stack trace. If there is, then [edit] your question and post it. – Abra Nov 25 '22 at 15:50
  • Exactly referring on JDateChooser. – SonyGame Nov 25 '22 at 15:52
  • [How to get parsed Date from Sqlite3 databse with Java?](https://stackoverflow.com/questions/30397988/how-to-get-parsed-date-from-sqlite3-databse-with-java) – Abra Nov 25 '22 at 16:43

0 Answers0