mysql 5.7 版本,建表語句mysql
CREATE TABLE `people` ( `job_number` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '員工ID', `name` varchar(32) NOT NULL COMMENT '姓名', `age` int(11) DEFAULT NULL COMMENT '年齡', `gender` varchar(1) DEFAULT NULL COMMENT '性別', `dept_id` int(11) DEFAULT NULL COMMENT '部門ID', `salary` decimal(12,4) DEFAULT NULL COMMENT '工資', `create_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`job_number`) ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COMMENT='新員工表'
能夠看到create_time的default 是 0000-00-00 00:00:00, 但在使用jdbc寫入時,若是傳參爲null,則默認寫入時間是當前時間...sql
例如:url
final Connection conn = DriverManager.getConnection(url , username , password ) ; conn.setAutoCommit(false); Row row = it.next(); String insert = "insert into people(name,create_time) values(?,?) "; PreparedStatement ps = (PreparedStatement) conn.prepareStatement(insert); ps.setObject(1, "John"); ps.setObject(2, null/*row.getAs("create_time")*/); ps.addBatch(); ps.executeBatch(); conn.commit();
有點神奇,記錄一下,哈哈哈。。code