Results 1 to 3 of 3
  1. #1
    Levian is offline Senior Member
    Join Date
    Jun 2011
    Posts
    109
    Rep Power
    0

    Default JXDatePicker problem

    Here's a part of my code
    Java 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 :
    Java 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.
    Last edited by Levian; 08-15-2011 at 02:29 AM.
    First is to make something usable, next is to aim for perfection which means a never ending improvements.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    The sql.Date.valueOf method needs a date in the format "yyyy-MM-dd" not "dd/MM/yyyy"

  3. #3
    Levian is offline Senior Member
    Join Date
    Jun 2011
    Posts
    109
    Rep Power
    0

    Default

    I see, thanks...that solves the problem.
    First is to make something usable, next is to aim for perfection which means a never ending improvements.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •