天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

解析MySql與Java的時間類型

MySql的時間類型有          Java中與之對應的時間類型
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 主站蜘蛛池模板: 冈本视频黄页正版 | 嫩草影院未满十八岁禁止入内 | 精品伊人久久久 | 美国CERANETWORK超清 | 一级am片欧美 | 欧美做真爱欧免费看 | 欧美亚洲精品真实在线 | 日本无吗高清 | 国产成人精品亚洲线观看 | 国产1769一七六九视频在线 | 国产一卡2卡3卡4卡孕妇网站 | 亚洲色婷婷久久精品AV蜜桃 | 欧美 亚洲综合在线一区 | 男男被强bl高h文 | 亚洲视频国产在线精品 | 二色AV天堂在线 | 色拍拍噜噜噜久久蜜桃 | japanese幼儿videos| 国内九一激情白浆发布 | 97国产成人精品视频 | 国产精品福利片 | 4虎影院午夜在线观看 | 囯产愉拍亚洲精品一区 | 探花口爆颜射乳交日韩 | 欧美xxxxxbb| 亚洲精品国偷拍自产在线观看蜜臀 | 强上轮流内射高NP男男 | babesvideos欧美最新 | 草莓视频app深夜福利 | 无罩看奶禁18 | 99热久久视频只有精品6国产 | 国产睡熟迷奷系列精品 | 无码日韩人妻精品久久蜜桃入口 | 欧美另类z0z000高清 | 国产亚洲日韩在线播放不卡 | 大肥婆丰满大肥奶bbw肥 | gv肉片视频免费观看 | 免费光看午夜请高视频 | 最近中文字幕MV高清在线 | qvod激情图片| 极品美女穴 |