Java get current time insert Database __ Database

Source: Internet
Author: User
Java.util.Date wants to replace the data java.sql.Date in SQL with the
java.util.Date subclass:
//Get current system time and convert to SQL date type
Java.util.Date  date=new java.util.Date ();
Java.sql.Date  sqldate=new java.sql.Date (Date.gettime ());
Insert the database table again
ps_publishlog.setdate (5,sqldate);

The date in Java is then converted to date in SQL, and you can simplify it as needed, 
Sqldate is the current time and has been converted to a DateTime type that can be inserted into the database.

or use MySQL to get the timestamp method, insert the time directly:
Gets the current date + time (date + times) function: Now () 
inserts into table (Name,age,time) VALUES (?,?, today ());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.