随笔-71  评论-5  文章-0  trackbacks-0


刚刚调试接口,sql 查询时 遇到一个问题,报错  “java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

其原因是数据库字段存在这样的值



百度了下:
这是因为 “0000-00-00 00:00:00”在mysql中是作为一个特殊值存在的,但是在Java中, java.sql.Date 会被视为 不合法的值,被JVM认为格式不正确。

解决办法:

在jdbc的url加上   zeroDateTimeBehavior参数:

datasource.url=jdbc:mysql://localhost:3306/pe?useUnicode=true&characterEncoding=gbk &zeroDateTimeBehavior=convertToNull


   完了过后,报异常

The reference to entity "characterEncoding" must end with the ';' delimiter   

其原因可能是在Properties文件或者xml文件中忘记进行特殊符号的转译了,


      需要把后面的;修噶为&修改为

useUnicode=true&characterEncoding=UTF-8 &zeroDateTimeBehavior=convertToNull 

有以下几类字符要进行转义替换:

<

<

小于号

&gt;

>

大于号

&amp;

&

&apos;

'

单引号

&quot;

"

双引号



问题解决





posted on 2014-12-30 11:37 藤本蔷薇 阅读(209) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: