The default value of mysql does not support functions and the default time is set. Java code because the default value of the current MySQL field does not support functions, it is impossible to set the default value in the form of create_time datetime default now.
The alternative is to use the TIMESTAMP type instead of the DATETIME type. The TIMESTAMP column type Automatically marks the INSERT or UPDATE operation with the current date and time. If multiple TIMESTAMP columns exist, only the first one is automatically updated. The first TIMESTAMP column is automatically updated at www.2cto.com under any of the following conditions: 1. The column value is not explicitly specified in an INSERT or load data infile statement.
2. The column value is not explicitly specified in an UPDATE statement and other columns change the value. (Note that setting an UPDATE column as its existing value does not cause the TIMESTAMP column to be updated, because if you set a column as its current value, MySQL ignores the changes for efficiency .) 3. you explicitly set the TIMESTAMP column as NULL. 4. the TIMESTAMP column except the first one can also be set to the current date and time, as long as the column is set to NULL, or NOW (). In addition, you can also use trigger to implement this function in Versions later than 5.0. Create table test_time (id int (11), create_time datetime); delimiter | create trigger default_datetime before insert on test_time for each row if new. create_time is null then set new. create_time = now (); end if; | delimiter; www.2cto.com Java code mysql how to set the default time to the current time? Set the date type to timestamp. You can create table 'dtal' ('uname' varchar (50) not null, 'udate' timestamp null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP) ENGINE = InnoDB default charset = utf8; if you want to operate under navicat, set the field to timestamp, and enter CURRENT_TIMESTAMP as the DEFAULT value.