|
date Java.sql.Date
Datetime Java.sql.Timestamp
Timestamp Java.sql.Timestamp
Time Java.sql.Time
Year Java.sql.Date
對其進行分析
參考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 的方式進行該類字段的顯示。添加該類字段數據,即可以使用字符串類型,也可以使用數字類型
由于Date類型的字段只記錄日期信息,所以如果添加的數據中包含了時間信息,該時間信息將會自動被截斷。
如果要保存時間信息,可以考慮使用DateTime類型。
經過測試,發現如下2種方式可以對Date類型字段進行填充:
按字符串:
insert into time_table(CreateDate) values(‘2007-04-09')
按數字:
insert into time_table(CreateDate) values(20070409)
獲取可以用Java.sql.Date類型獲取
代碼為:
Date dtDate =rsBuffer.getDate("CreateDate");
測試代碼如下:(其中,IDBFace 是自己基于JDBC封裝的一個簡單類, 接受Sql對數據庫進行操作)
復制代碼 代碼如下:
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();
}
執行結果: 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最主要的區別在于:DateTime 可以記錄日期和時間信息。而Date只記錄日期信息。表示范圍為: 1000-01-01 00:00:00 至 9999-12-31 23:59:59 MySql的按照YYYY-MM-DD HH:MM:SS對數據進行格式化,允許以字符串和數字的方式提交。
例如以數字的方式進行提交:
insert into time_table(CreateDate) values(20070409132013)
獲取該類型的數據可以使用:Java.sql.Timestamp類型
代碼如下:
復制代碼 代碼如下:
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();
}
執行結果: 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 主站蜘蛛池模板: 罗米欧与朱丽叶| charlie sheen| 心花路放 豆瓣| 保镖 电影在线观看 完整版| 退社申请书800字| 大唐狄公案电视剧演员表| 微笑江湖| 西安地铁2号线运营时间表| 孤岛惊魂| cctv16体育台节目表| 不得不爱吉他谱| 性视频动态图| 漫画启示作文五年级| 巧巧| 成龙版杨家将电影免费播放| 许多组织都有自己的价值标准和行为理念 | 血色樱花剧情介绍| 爸爸好奇怪 电视剧| 超级小熊布迷全集免费观看| 我是特种兵之火凤凰演员表全部| 三年片电影| hd经典复古性mature| 回魂夜 电影| 大空头 电影| 女攻男受调教道具| 朝雪录电视剧免费观看全集完整版| 醉翁亭记理解性默写及答案| 男同性网站| 搜狐视频官网| 茅山道士在线观看| 电影偿还| 小猪佩奇最新第十季| 路易斯·帕特里奇| 褚阳| 抖音视频下载网站| 东方电视台节目表今日节目| 物理必修三目录图片| 柯特妮·考克斯| 情侣不雅视频| 黄造时曹查理隔世情电影| 电影壮志凌云女版满天星法版在线看 |