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