Java Timestamp to MySQL Timestamp -


i have code, not working. have error message:

"com.mysql.jdbc.mysqldatatruncation: data truncation: incorrect datetime value: '' column 'datum_zalozeni' @ row 1"

  pstmt = conn.preparestatement(insert);                 timestamp ts = u.getdatum_zalozeni();                 system.out.println(ts);                 pstmt.settimestamp(1, ts);                 pstmt.setint(2, u.getid_klient());                 pstmt.executeupdate(); 

my database is:

create table ucet (   id_uctu int not null auto_increment primary key,   datum_zalozeni timestamp not null,   id_klient int not null ) ; 

where mistake? think code correct.

i have code generate system timestamp. sets 0 in place of 979. have look.

import java.sql.timestamp; import java.text.dateformat; import java.text.parseexception; import java.text.simpledateformat; import java.util.calendar; import java.util.date;  public class timestamptest { public static void main(string[] args) {     try     {         system.out.println("system date: " + generatetimestamp("yyyy-mm-dd hh:mm:ss"));     }     catch (exception e)     {         e.printstacktrace();     } }  public static timestamp generatetimestamp(string format) {     timestamp timestamp = null;      try     {         simpledateformat dateformat = new simpledateformat(format);          date date = dateformat.parse(generatedate(format));          timestamp = new timestamp(date.gettime());     }     catch (parseexception e)     {         e.printstacktrace();     }      return timestamp; }  public static string generatedate(string format) {     date date = calendar.getinstance().gettime();      dateformat dateformat = new simpledateformat(format);      return (dateformat.format(date)); } } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -