java - Passing DateTime to string for SQL -


i using datetimepicker class gui building, need use value selected user part of future sql query, cant seem datetime value string pass database.

the datetimepicker class

import org.jdesktop.swingx.calendar.singledayselectionmodel; import org.jdesktop.swingx.jxdatepicker;  import javax.swing.*; import javax.swing.text.defaultformatterfactory; import javax.swing.text.dateformatter; import java.text.dateformat; import java.text.parseexception; import java.util.*; import java.awt.*;  /**  * licensed under lgpl.  license can found here:  http://www.gnu.org/licenses/lgpl-3.0.txt  *  * provided is.  if have questions please direct them charlie.hubbard @ gmail dot know what.  */ public class datetimepicker extends jxdatepicker {     private jspinner timespinner;     private jpanel timepanel;     private dateformat timeformat;      public datetimepicker() {         super();         getmonthview().setselectionmodel(new singledayselectionmodel());     }      public datetimepicker( date d ) {         this();         setdate(d);     }      public void commitedit() throws parseexception {         committime();         super.commitedit();     }      public void canceledit() {         super.canceledit();         settimespinners();     }      @override     public jpanel getlinkpanel() {         super.getlinkpanel();         if( timepanel == null ) {             timepanel = createtimepanel();         }         settimespinners();         return timepanel;     }      private jpanel createtimepanel() {         jpanel newpanel = new jpanel();         newpanel.setlayout(new flowlayout());         //newpanel.add(paneloriginal);          spinnerdatemodel datemodel = new spinnerdatemodel();         timespinner = new jspinner(datemodel);         if( timeformat == null ) timeformat = dateformat.gettimeinstance( dateformat.short );         updatetextfieldformat();         newpanel.add(new jlabel( "time:" ) );         newpanel.add(timespinner);         newpanel.setbackground(color.white);         return newpanel;     }      private void updatetextfieldformat() {         if( timespinner == null ) return;         jformattedtextfield tf = ((jspinner.defaulteditor) timespinner.geteditor()).gettextfield();         defaultformatterfactory factory = (defaultformatterfactory) tf.getformatterfactory();         dateformatter formatter = (dateformatter) factory.getdefaultformatter();         // change date format show hours         formatter.setformat( timeformat );     }      private void committime() {         date date = getdate();         if (date != null) {             date time = (date) timespinner.getvalue();             gregoriancalendar timecalendar = new gregoriancalendar();             timecalendar.settime( time );              gregoriancalendar calendar = new gregoriancalendar();             calendar.settime(date);             calendar.set(calendar.hour_of_day, timecalendar.get( calendar.hour_of_day ) );             calendar.set(calendar.minute, timecalendar.get( calendar.minute ) );             calendar.set(calendar.second, 0);             calendar.set(calendar.millisecond, 0);              date newdate = calendar.gettime();             setdate(newdate);         }      }      private void settimespinners() {         date date = getdate();         if (date != null) {             timespinner.setvalue( date );         }     }      public dateformat gettimeformat() {         return timeformat;     }      public void settimeformat(dateformat timeformat) {         this.timeformat = timeformat;         updatetextfieldformat();     }       public static void main(string[] args) {         date date = new date();         jpanel frame = new jpanel();         datetimepicker datetimepicker = new datetimepicker();         datetimepicker.setformats( dateformat.getdatetimeinstance( dateformat.short, dateformat.medium ) );         datetimepicker.settimeformat( dateformat.gettimeinstance( dateformat.medium ) );          datetimepicker.setdate(date);          frame.add(datetimepicker);         frame.setvisible(true);     } } 

and part of gui class @ minute want when button presses change output on textfeild current datetime of picker

jpanel panel = new jpanel(); panel.add(dtp); panel.setbounds(12, 204, 206, 39); frame.getcontentpane().add(panel);   jpanel panel_1 = new jpanel(); panel_1.add(dtp2); panel_1.setbounds(12, 255, 206, 39); frame.getcontentpane().add(panel_1);  textfield = new jtextfield(); textfield.setbounds(12, 322, 250, 30); frame.getcontentpane().add(textfield); textfield.setcolumns(10);  jbutton btnadder = new jbutton("adder"); btnadder.addactionlistener(new actionlistener() {     public void actionperformed(actionevent e) {         string dt = dtp.getname().tostring();         textfield.settext(dt);     } }); btnadder.setbounds(230, 258, 117, 25); frame.getcontentpane().add(btnadder); 

}

i'm not sure have tried passing datetime in different ways , bit confused on do!!

at minute button press gives me:

datetimepicker[,30,5,145x23,invalid,layout=org.jdesktop.swingx.plaf.basic.basicdatepickerui$handler,alignmentx=0.0,alignmenty=0.0,border=,flags=320,maximu 

i think mismatch dont know how combat this!

any great!!!

cheers guys!


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -