posts - 15,  comments - 34,  trackbacks - 27

          SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd"); //格式化當前系統日期
          qds.setDate("制單日期", Date.valueOf(dateFm.format(new java.util.Date())));

          此種情況數據庫的字段為Date型

          ------------------------------------------------------------------------------------------------------------

          String 制單日期 = MessageFormat.format("{0,date,yyyy-MM-dd HH:mm:ss}", new Object[] { new java.sql.Date(System.currentTimeMillis()) });
          qds.setTimestamp("制單日期", Timestamp.valueOf(制單日期)); // 不能強行轉換

          此種情況數據庫的字段為Timestamp(6)型

          ---------------------------------------------------------------------------------------------------------

          附:幾個Date類的valueOf()方法

          1. java.sql.Date.valueOf(java.lang.String)

              public static Date valueOf(String s)
           Converts a string in JDBC date escape format to a Date value.

           Parameters:
           s - a String object representing a date in in the format "yyyy-mm-dd"
           Returns:
           a java.sql.Date object representing the given date
           Throws:
           IllegalArgumentException - if the date given is not in the JDBC date escape format (yyyy-mm-dd)

          2. java.sql.Time.valueOf(java.lang.String)

              public static Time valueOf(String s)
           Converts a string in JDBC time escape format to a Time value.

           Parameters:
           s - time in format "hh:mm:ss"
           Returns:
           a corresponding Time object

          3. java.sql.Timestamp.valueOf(java.lang.String)
            
             public static Timestamp valueOf(String s)
           Converts a String object in JDBC timestamp escape format to a Timestamp value.

           Parameters:
           s - timestamp in format yyyy-mm-dd hh:mm:ss.fffffffff
           Returns:
           corresponding Timestamp value
           Throws:
           IllegalArgumentException - if the given argument does not have the format yyyy-mm-dd hh:mm:ss.fffffffff



          本文引用通告地址: http://blog.csdn.net/jwbecalm/services/trackbacks/444843.aspx
          posted on 2005-08-28 05:26 jacky 閱讀(1935) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2005年8月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          常用鏈接

          留言簿(10)

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          java

          搜索

          •  

          最新評論


          主站蜘蛛池模板: 太康县| 崇州市| 法库县| 土默特左旗| 恩施市| 云南省| 文成县| 大同市| 九龙坡区| 岗巴县| 喀什市| 千阳县| 陆丰市| 崇义县| 南京市| 乌兰察布市| 安阳市| 万荣县| 旬阳县| 弋阳县| 隆林| 瓮安县| 伊春市| 平利县| 长子县| 洪江市| 阜新| 祁东县| 页游| 灵丘县| 云霄县| 盐边县| 天峻县| 姜堰市| 长海县| 柳林县| 伊通| 阜康市| 丽江市| 宾川县| 开江县|