The use of the Now () function in MySQL, as well as the sysdate of Oracle

Source: Internet
Author: User

The use of the Now () function in MySQL, as well as the sysdate of Oracle

In the demand if the system of traditional Chinese medicine add the time of the current operation so simple an operation in writing SQL directly in the field corresponding to the location of the now () function can be, so less a lot of code, especially in the use of JDBC when writing, you can write less about the placeholder code, However, there is an implicit premise is that the database and the server is on the same machine , if not on the same machine, then this is a hole, I think there is no experience, did not fall into the pit of the people will write, such as Me, Lazy will write like this. When this time is used to compare or judge the business logic, the pit appears.

LZ in the location of the problem to do business when encountered, at that time, the server in the LZ computer, the database at the far end, because the business needs to adjust the time to the next point of time, and then began to do, but then after 1 weeks or so, accidentally found a table with the time unexpectedly when the current is really time, I have such speculation , there should be a programmer using the Sysdate field. Although not obviously found, but it should be used, or will not take the real time ah. In particular, some of the projects that require remote debugging, colleagues for coding specifications, I think the code of the SQL coding also to add this.

LZ did not understand and did such things, now can only remind you not to do so, and then get rid of their own recently written code.

It is recommended that you generate a new time object in Java, and if you use JDBC directly in SQL, do not use placeholders.

//this is written in DAO.Member (Name,pw,register_time) value (?,?, ' "+dbassitor.sdfyyyymmddhhmmss.format (New Date ()) +" '); ";//The database helper class defines an SDF class Public classdbassitor{/**operation results in database related operations are not affecting the number of rows * **/     Public Static intNo_affect_row = 0;  Public StaticString Sdfyyyymmddhhmmss_ = "Yyyy-mm-dd HH:mm:ss";  Public StaticSimpleDateFormat SDFYYYYMMDDHHMMSS =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");}

The use of the Now () function in MySQL, as well as the sysdate of Oracle

Related Article

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.