中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

解析MySql與Java的時間類型

MySql的時間類型有          Java中與之對應(yīng)的時間類型
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 的方式進行該類字段的顯示。添加該類字段數(shù)據(jù),即可以使用字符串類型,也可以使用數(shù)字類型

由于Date類型的字段只記錄日期信息,所以如果添加的數(shù)據(jù)中包含了時間信息,該時間信息將會自動被截斷。
如果要保存時間信息,可以考慮使用DateTime類型。
經(jīng)過測試,發(fā)現(xiàn)如下2種方式可以對Date類型字段進行填充:
按字符串:
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");
測試代碼如下:(其中,IDBFace 是自己基于JDBC封裝的一個簡單類, 接受Sql對數(shù)據(jù)庫進行操作)
復(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 可以記錄日期和時間信息。而Date只記錄日期信息。表示范圍為: 1000-01-01 00:00:00 至 9999-12-31 23:59:59 MySql的按照YYYY-MM-DD HH:MM:SS對數(shù)據(jù)進行格式化,允許以字符串和數(shù)字的方式提交。

例如以數(shù)字的方式進行提交:
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 主站蜘蛛池模板: h视频在线播放 | 日韩中文一区二区三区 | 一区二区国产精品 | 超碰人人人 | 一区二区三区av | 欧美一区二区三区精品免费 | 久草中文在线 | 99精品视频免费在线观看 | 国产在线观看 | 久久综合激情 | 成人欧美一区二区 | 欧美一区二区三区四区五区无卡码 | 亚洲一区二区中文字幕 | 亚洲精品小视频在线观看 | 午夜精品网站 | 国产在线观看不卡一区二区三区 | 蜜桃一区二区三区在线 | 69xxx免费| 在线成人免费观看 | 中文在线一区二区 | 国产精品一区一区 | 在线色| 成人黄色在线视频 | 日日夜夜天天久久 | 做a视频在线观看 | 亚洲精品大片 | 国产免费观看一级国产 | 亚洲精品在线视频 | 在线视频99 | 久久99精品久久久久久国产越南 | 欧美精品一区在线观看 | 91黄在线观看 | 亚洲一区网站 | 国产亚洲精品久久久久久牛牛 | 亚洲综合大片69999 | 国产电影一区二区 | 国产成人综合在线 | 国产成人网 | 中文字幕一区二区视频 | 日本高清在线一区 | 日韩中文字幕在线观看 |