ゞ沉默是金ゞ

          魚離不開水,但是沒有說不離開哪滴水.
          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認為這個不是一個有效的時間字串。

          而有效的日期格式為“ 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.
          當這些值正在從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.
          依照JDBC和SQL的標準這些值碰到的最正確的處理方式就是在缺省情況下產(chǎn)生異常
          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 ゞ沉默是金ゞ 閱讀(5954) 評論(0)  編輯  收藏 所屬分類: DB
          主站蜘蛛池模板: 宁陕县| 遵化市| 双江| 新昌县| 石楼县| 监利县| 凤城市| 普定县| 华池县| 马公市| 莱州市| 泌阳县| 尖扎县| 和平区| 黄山市| 竹山县| 樟树市| 乌兰浩特市| 尖扎县| 赤水市| 龙南县| 睢宁县| 囊谦县| 灌阳县| 淅川县| 中超| 封开县| 尚义县| 临湘市| 买车| 绍兴市| 周口市| 嫩江县| 焦作市| 青河县| 广灵县| 阿城市| 浦县| 确山县| 邵东县| 扶沟县|