|
date Java.sql.Date
Datetime Java.sql.Timestamp
Timestamp Java.sql.Timestamp
Time Java.sql.Time
Year Java.sql.Date
對(duì)其進(jìn)行分析
參考MySql 的reference manual
Date:
A date. The supported range is '1000-01-01' to '9999-12-31'. MySQL displays DATE values in 'YYYY-MM-DD' format, but allows you to assign values to DATE columns using either strings or numbers.
只記錄日期信息,表示范圍為1000-01-01 至 9999-12-31。
MySql 按照YYYY-MM-DD 的方式進(jìn)行該類字段的顯示。添加該類字段數(shù)據(jù),即可以使用字符串類型,也可以使用數(shù)字類型
由于Date類型的字段只記錄日期信息,所以如果添加的數(shù)據(jù)中包含了時(shí)間信息,該時(shí)間信息將會(huì)自動(dòng)被截?cái)唷?BR>如果要保存時(shí)間信息,可以考慮使用DateTime類型。
經(jīng)過(guò)測(cè)試,發(fā)現(xiàn)如下2種方式可以對(duì)Date類型字段進(jìn)行填充:
按字符串:
insert into time_table(CreateDate) values(‘2007-04-09')
按數(shù)字:
insert into time_table(CreateDate) values(20070409)
獲取可以用Java.sql.Date類型獲取
代碼為:
Date dtDate =rsBuffer.getDate("CreateDate");
測(cè)試代碼如下:(其中,IDBFace 是自己基于JDBC封裝的一個(gè)簡(jiǎn)單類, 接受Sql對(duì)數(shù)據(jù)庫(kù)進(jìn)行操作)
復(fù)制代碼 代碼如下:
public void testDate()throws SQLException
{
IDBFace DBFace =DBFactory.createMySqlFace();
DBFace.connect();
//清空表
String strDelete ="delete from time_table";
DBFace.update(strDelete);
//添加
String strInsert ="insert into time_table(CreateDate) values(20070409)";
DBFace.update(strInsert);
//獲取
String strSelect ="select * from time_table";
ResultSet rsBuffer =DBFace.select(strSelect);
while(rsBuffer.next())
{
Date dtDate =rsBuffer.getDate("CreateDate");
System.out.println(dtDate.toString());
}
DBFace.close();
}
執(zhí)行結(jié)果: 2007-04-09
DateTime
A date and time combination. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. MySQL displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format, but allows you to assign values to DATETIME columns using either strings or numbers.
DateTime 與Date最主要的區(qū)別在于:DateTime 可以記錄日期和時(shí)間信息。而Date只記錄日期信息。表示范圍為: 1000-01-01 00:00:00 至 9999-12-31 23:59:59 MySql的按照YYYY-MM-DD HH:MM:SS對(duì)數(shù)據(jù)進(jìn)行格式化,允許以字符串和數(shù)字的方式提交。
例如以數(shù)字的方式進(jìn)行提交:
insert into time_table(CreateDate) values(20070409132013)
獲取該類型的數(shù)據(jù)可以使用:Java.sql.Timestamp類型
代碼如下:
復(fù)制代碼 代碼如下:
public void testDateTime() throws SQLException
{
IDBFace DBFace =DBFactory.createMySqlFace();
DBFace.connect();
//清空表
String strDelete ="delete from time_table";
DBFace.update(strDelete);
//添加
String strInsert ="insert into time_table(CreateDateTime) values(20070409132013)";
DBFace.update(strInsert);
//獲取
String strSelect ="select * from time_table";
ResultSet rsBuffer =DBFace.select(strSelect);
while(rsBuffer.next())
{
Timestamp tsBuffer =rsBuffer.getTimestamp("CreateDateTime");
System.out.println(tsBuffer.toString());
}
DBFace.close();
}
執(zhí)行結(jié)果: 2007-04-09 13:20:13.0
TimeStamp
A timestamp. The range is '1970-01-01 00:00:00' to partway through the year 2037. A TIMESTAMP column is useful for recording the date and time of an INSERT or UPDATE operation. The first TIMESTAMP column in a table is automatically set to the date and time of the most recent operation if you don't assign it a value yourself. You can also set any TIMESTAMP column to the current date and time by assigning it a NULL value.
與DateTime類型非常相似
范圍為1970-01-01 主站蜘蛛池模板: 精品AV国产一区二区三区 | 日韩性大片 | 男人天堂黄色 | 大胸美女裸身色诱网站 | 中文字幕乱码亚洲无线三区 | 闺蜜撬开我的腿用黄瓜折磨我 | 午夜国产羞羞视频免费网站 | 麻豆精品传媒一二三区 | 最新日本免费一区 | 国产精品成人影院 | 99久久夜色精品国产亚洲AV卜 | 伊人综合在线影院 | 伊人无码高清 | 毛片在线网址 | 中文字幕久久熟女人妻AV免费 | 久久影院毛片一区二区 | 午夜福利体验试看120秒 | 极品少妇高潮啪啪AV无码 | 久久久高清国产999尤物 | 特级aa 毛片免费观看 | 免费中文字幕视频 | 永久免费精品影视网站 | 两性午夜色视频免费网站 | 欧美性极品黑人hd | thermo脱色摇床安卓下载 | 久久资源365 | 久久久无码精品无码国产人妻丝瓜 | 国产Av男人的天堂精品良久 | 办公室里做好紧好爽H | 天天躁日日躁狠狠躁中文字幕老牛 | 野花日本大全免费观看3中文版 | 99热只有这里有精品 | 甜涩性爱下载 | 伊人久久大香线蕉综合电影 | 国产精品一区二区亚瑟不卡 | 美女脱了内裤张开腿让男人爽 | 国产av在线看的 | 97亚洲狠狠色综合久久位 | 国产高清亚洲日韩字幕一区 | 99热成人精品国产免男男 | 一级做a爰片久久毛片苍井优 |