-
JXDatePicker problem
Here's a part of my code
Code:
private boolean isNewSKDate() {
JXDatePicker dtYear = new JXDatePicker();
SimpleDateFormat dtdf = new SimpleDateFormat ("dd/MM/yyyy");
try {
qyear.setQuery("SELECT actyear FROM temp WHERE (nik = '" + txNIK.getText() + "' AND actyear = '" + Date.valueOf(dtdf.format(dtYear.getDate())) + "');");
// qyear.setQuery("SELECT actyear FROM temp WHERE (nik = '" + txNIK.getText() + "' AND actyear = '" + Date.valueOf(txYear.getText().toString().trim().replace(" 00:00:00.0", "")) + "');");
} catch (SQLException e) {
e.printStackTrace();
}
Component frame = null;
if (qyear.getRowCount() == 0) {
return true;
} else if (qyear.getRowCount() > 0) {
JOptionPane.showMessageDialog(frame, "Check SK Date.");
return false;
};
qyear.cache.clear();
return rootPaneCheckingEnabled;
}
I tried to change my textfield into a jxdatepicker (commenting my previous textfield part), but the part on checking the date is not working, though in the other part of the code the same getDate() works fine, I can't really figure out where the problem is.
Error message that I get is :
Code:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException
at java.sql.Date.valueOf(Unknown Source)
at trndev.ActModMS.isNewSKDate(ActModMS.java:63)
at trndev.ActModMS.access$8(ActModMS.java:59)
at trndev.ActModMS$6.actionPerformed(ActModMS.java:449)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
at trndev.ActModMS.isNewSKDate(ActModMS.java:63) refers to this line :
qyear.setQuery("SELECT actyear FROM temp WHERE (nik = '" + txNIK.getText() + "' AND actyear = '" + Date.valueOf(dtdf.format(dtYear.getDate())) + "');");
at trndev.ActModMS.access$8(ActModMS.java:59) refers to private boolean isNewSKDate() {
at trndev.ActModMS$6.actionPerformed(ActModMS.java:44 9) refers to another part in the code where isNewSKDate() is called for checking the datetime.
Thanks in advance.
-
The sql.Date.valueOf method needs a date in the format "yyyy-MM-dd" not "dd/MM/yyyy"
-
I see, thanks...that solves the problem.