Storing default value for incorrect timestamps
Rohit Harchandani <[email protected]> Thu, 31 Aug 2017 04:53:51 +0000
| Newsgroups | gmane.comp.db.mysql.java |
|---|---|
| Message-ID | <MWHPR16MB1773DC0165B99FAA9DC68D73959D0@MWHPR16MB1773.namprd16.prod.outlook.com> |
--_000_MWHPR16MB1773DC0165B99FAA9DC68D73959D0MWHPR16MB1773namp_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, Below is my current mysql setup: Version: 5.7 sql_mode=3D'' time_zone=3DSYSTEM system_time_zone=3DPDT Table 'test' with 2 columns: +-------------+-----------+------+-----+---------------------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-----------+------+-----+---------------------+-------+ | Roles | int(11) | NO | PRI | NULL | | | DateUpdated | timestamp | NO | | 0000-00-00 00:00:00 | | +-------------+-----------+------+-----+---------------------+-------+ When I use mysql command line client to insert a row as below, insert into test (`roles`, `dateupdated`) values (1, '1969-12-31 16:00:00')= ; it gives a warning due to an out of range date but the row does get inserte= d +-------+---------------------+ | Roles | DateUpdated | +-------+---------------------+ | 1 | 0000-00-00 00:00:00 | +-------+---------------------+ However, when I use JDBI/JDBC to do perform the same insert, I get the foll= owing error: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime val= ue: '1969-12-31 16:00:00' for column 'DateUpdated' at row 1 What is the reason for this difference? How do I get my java program to ins= ert the "0000-00-00 00:00:00" value for the DateUpdated field and behave li= ke the mysql command line client does? Thanks, Rohit --_000_MWHPR16MB1773DC0165B99FAA9DC68D73959D0MWHPR16MB1773namp_--