Java Error Series--java.util.date/java.sql.date/java.sql.timestamp

Source: Internet
Author: User

Objective

A few days ago, in the project, encountered a problem, the situation is very simple, is taken from the MySQL database time only month day, and no time and seconds. Then, the first instinct is definitely I import the package has a problem, sure enough, I imported the java.sql.Date package, fixed to java.util.Date, the problem is still. What is this for? Once remember, Java.util.Date will take out the date + time, and Java.sql.Date will only have a date. Is this the right one? The time type of MySQL is often datetime/timestamp, what should we do?


Experiment

MySQL Table preparation:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6F/04/wKiom1WPXmjizWOBAABAGrM-plM065.jpg "title=" Sogou _ 2015-06-28_10-39-04.png "alt=" Wkiom1wpxmjizwobaabagrm-plm065.jpg "/>



Code:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6F/00/wKioL1WPYQjynzwAAAOulCkNouM101.jpg "title=" Sogou _ 2015-06-28_10-43-10.png "alt=" Wkiol1wpyqjynzwaaaoulcknoum101.jpg "/>



Output:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6F/04/wKiom1WPX3-THQmKAAE2cGmcN6s150.jpg "title=" Sogou _ 2015-06-28_10-44-01.png "alt=" Wkiom1wpx3-thqmkaae2cgmcn6s150.jpg "/>



Conclusion

Regardless of the MySQL time data type is datetime/timestamp, if we just need the date part, then java.util.date/java.sql.date can be used; if we need a date + time, Then the Java.sql.Timestamp type should be used.







This article is from the "Hard Struggle" blog, please make sure to keep this source http://zhangfengzhe.blog.51cto.com/8855103/1668670

Java Error Series--java.util.date/java.sql.date/java.sql.timestamp

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.