ゞ沉默是金ゞ

          魚離不開水,但是沒有說不離開哪滴水.
          posts - 98,comments - 104,trackbacks - 0

          使用hibernate開發程序的時候,有的時間字段沒有必要填寫,但是,以后hibernate查詢的時候會報出

          java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp

          的錯誤, 這是因為hibernate認為這個不是一個有效的時間字串。

          而有效的日期格式為“ 0001-01-01   00:00:00.0 ”


          查看了mysql5的幫助文檔對于datetime的解釋如下

          Datetimes with all-zero components (0000-00-00 ...) — These values can not be represented 關于所有Datetime類型由0組成的數據,這些值不能在java中被可靠的表示
          reliably in Java.
          Connector/J 3.0.x always converted them to NULL when being read from a ResultSet.
          當這些值正在從ResultSet容器中讀取時候,Connector/J 3.0.x 一直把他們轉換為NULL值。

          Connector/J 3.1 throws an exception by default when these values are encountered as this is the most correct behavior according to the JDBC and SQL standards.
          依照JDBC和SQL的標準這些值碰到的最正確的處理方式就是在缺省情況下產生異常
          This behavior can be modified using the zeroDateTimeBehavior configuration property. The allowable values are:
          JDBC允許用下列的值對zeroDateTimeBehavior 屬性來設置這些處理方式,

          exception (the default), which throws an SQLException with an SQLState of S1009.
          設置為exception 異常(缺省)用一個SQLState的s1009錯誤號來拋出一個異常
          convertToNull, which returns NULL instead of the date.
          設置為convertToNull,用NULL值來代替這個日期類型
          round, which rounds the date to the nearest closest value which is 0001-01-01.
          設置為round,則圍繞這個日期最接近的值(0001-01-01)來代替

           

          修改你的jdbc連接

          jdbc:mysql://localhost/schoolmis?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull

          posted on 2009-06-20 15:20 ゞ沉默是金ゞ 閱讀(5960) 評論(0)  編輯  收藏 所屬分類: DB
          主站蜘蛛池模板: 连州市| 达拉特旗| 金湖县| 斗六市| 汉寿县| 保靖县| 静乐县| 洞头县| 黄骅市| 金阳县| 健康| 隆安县| 磴口县| 温宿县| 吉首市| 江山市| 玉屏| 叙永县| 大同县| 山阳县| 潜山县| 莱州市| 台东市| 乌苏市| 呼玛县| 开封市| 上犹县| 松溪县| 安徽省| 镇赉县| 板桥市| 本溪市| 沂源县| 嘉荫县| 海宁市| 双辽市| 久治县| 平远县| 抚顺市| 潼南县| 嵊州市|