java - how to format date and time from JDateChooser to mysql datetime column -


I am trying to get the current date and time of my store from mysql database from JDateChooser, but it only incorporates today's date And the current time is 00: 00: 00

  java.util.Date dt1, dt2; String n = name.getText (); String i = id.getText (); SimpleDetformSDF = New SimpleDateform ("YYA-MM-DD"); DT1 = jDateChooser1.getDate (); DT2 = jDateChooser2.getDate (); String strdtver1 = (string) sdf.format (jDateChooser1.getDate ()); String strdtver2 = (string) sdf.format (jDateChooser2.getDate ()); Try {class.forName ("com.mysql.jdbc.Driver"); Connection con = (connection) DriverManager.getConnection ("jdbc: mysql: // localhost: 3306 / test", "root", ""); Statement stmt = con.createStatement (); Insert the string sql = "SS value ('+ + (n) +' ',' + (strdtver1) + '', '+ (strdtver2) +' ','" + (i) + "'); "; Stmt.executeUpdate (SQL); Employmentpan Show Messedidoug (This, "Record Successfully Entered"); } Hold (exception e) {JOptionPane.showMessageDialog (this, e.getMessage ()); }  

This is a program to check in & amp; Check the date and time DataType in MySQL is the dateotype for check_in and check_out column data recorded in my SQL on check_in 2014-10-27 00:00:00 The present date is correct but I present 00: 00: 00 instead of current time I want to insert Please help me

The date you get from widgets are formatting, but you only use a date pattern as a format string; Supported by mysql for date and time string format, use:

  SimpleDateFormat sdf = New SimpleDateFormat ("yyyy-MM-dd HH: mm: ss");  

Comments