简体   繁体   English

如何使用Java在MySql WorkBench中插入DateTime?

[英]How to insert DateTime in MySql WorkBench using java?

How can I store data time in my SQL Work Bench using java? 如何使用Java在SQL Work Bench中存储数据时间? I tried by Failed to do so. 我尝试失败了。 Want to insert current Date time in Order Column using Java 想要使用Java在“订单”列中插入当前日期时间

insert into customer_order (idCustomer_Order,Customer_id,Total_Amount,Payment,Order_date,Order_month,Order_year,Delivery_date,Delivery_month,Delivery_year,product_id,OrderDate)value(3,1,122,'payed',3,2,4,2,3,4,4,curdate())

i tried this but time is 00:00:00 3 1 122 payed 3 2 4 2 3 4 4 2017-12-28 00:00:00 我尝试了这个,但是时间是00:00:00 3 1122支付了3 2 4 2 3 4 4 2017-12-28 00:00:00

Use NOW() and it will add the current date time 使用NOW() ,它将添加当前日期时间

Your query should take the form 您的查询应采用以下形式

INSERT INTO customer_order (idCustomer_Order,Customer_id,Total_Amount,Payment,Order_date,Order_month,Order_year,Delivery_date,Delivery_month,Delivery_year,product_id,OrderDate)value(3,1,122,'payed',3,2,4,2,3,4,4, NOW())

I am using curDate() so that only date was inserting in database instead if i use current_timestamp() than i get date as well as time. 我正在使用curDate(),所以如果我使用current_timestamp(),则只有日期插入数据库中,而不是获取日期和时间。

insert into customer_order (OrderDate)value(current_timestamp())

Output is 2017-12-28 01:48:31 输出是2017-12-28 01:48:31

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM