1

I'm trying to get date from jDateChooser. So I used this update query. But now I'm getting this getDate() method as cannot find the symbol error. I'm using JDBC class. And following is my query:

try { 
        new JDBC().putData("UPDATE work SET balance='"+txtValue.getText()+"', date='"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date.getdate()) +"' WHERE id='1'");

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, this.getClass().getName() +" "+e);
    } 
Yubaraj
  • 3,800
  • 7
  • 39
  • 57
Dilini
  • 69
  • 4
  • 10
  • I can think of any number problems...How is `date` declared? Is it being shadowed by another local variable of a different type? – MadProgrammer Sep 18 '13 at 05:40
  • date is the column name in table and data type is DATETIME – Dilini Sep 18 '13 at 05:43
  • Sorry, how is the `date` object declared? Is it actually a `JDateChooser`? Is it shadowed by another local variable of a different type? – MadProgrammer Sep 18 '13 at 05:45
  • if you are talking about this. date.getdate() it is equal dateChooserCombo1.getDate() – Dilini Sep 18 '13 at 05:55
  • @Alex I tryed it. But same result I don't get getDate() as a valid method. – Dilini Sep 18 '13 at 05:57
  • Alright I'm confused, you say `date.getdate` is equal to `dateChooserCombo1.getDate()`, which I would assume then `date` is actually a `java.util.Date` object? – MadProgrammer Sep 18 '13 at 06:00

3 Answers3

2

You probably have error here:

date.getdate()

It should be capital D

date.getDate()
Alex
  • 11,451
  • 6
  • 37
  • 52
  • I used jDateChooser not dateChooserCombo and now that method is working. I don't know why. But thanks for your support. – Dilini Sep 18 '13 at 06:11
2

try this with JCalendar 1.4 ---------------------------------((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText()

1

Try this for latest version.

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = sdf.format(jDateChooser1.getSelectedDate().getTime());
  • this worked for me SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); String date = sdf.format(jDateChooser1.getDate()); – Khurram Ali Nov 24 '15 at 20:34