ゞ沉默是金ゞ

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

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

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

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

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


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

          Datetimes with all-zero components (0000-00-00 ...) — These values can not be represented 關(guān)于所有Datetime類型由0組成的數(shù)據(jù),這些值不能在java中被可靠的表示
          reliably in Java.
          Connector/J 3.0.x always converted them to NULL when being read from a ResultSet.
          當(dāng)這些值正在從ResultSet容器中讀取時候,Connector/J 3.0.x 一直把他們轉(zhuǎn)換為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.
          依照J(rèn)DBC和SQL的標(biāo)準(zhǔn)這些值碰到的最正確的處理方式就是在缺省情況下產(chǎn)生異常
          This behavior can be modified using the zeroDateTimeBehavior configuration property. The allowable values are:
          JDBC允許用下列的值對zeroDateTimeBehavior 屬性來設(shè)置這些處理方式,

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

           

          修改你的jdbc連接

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

          posted on 2009-06-20 15:20 ゞ沉默是金ゞ 閱讀(5955) 評論(0)  編輯  收藏 所屬分類: DB
          主站蜘蛛池模板: 涟源市| 泽库县| 彰武县| 三穗县| 呼图壁县| 重庆市| 金寨县| 北流市| 循化| 乐都县| 泰宁县| 灌云县| 天长市| 兖州市| 禹州市| 登封市| 奉节县| 开远市| 祁阳县| 垦利县| 通化县| 三明市| 石楼县| 弥勒县| 石城县| 武功县| 灵石县| 凯里市| 奈曼旗| 老河口市| 建平县| 日喀则市| 平江县| 凯里市| 镇原县| 无棣县| 天柱县| 和政县| 巴里| 来凤县| 竹山县|