您的位置:首页 > 数据库 > MySQL

Mysql JDBC Url参数与异常问题

2015-05-31 14:56 726 查看
今天在写Java项目使用了
<select id="getPlans" parameterType="hashMap" resultType="hashMap">
SELECT
*
FROM
`plan`
WHERE
isDelete=#{isDelete} AND nestId in
<foreach collection="nestIds" item="nestId" index="index"
open="(" close=")" separator=",">
#{nestId}
</foreach>
</select>
但是很不幸,后台报异常:
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
经过查找才发现是因为数据表有的addTime是“0000-00-00 00:00:00”,不论是Mybatis还是hibernate都认为不是一个有效的时间字串,而有效的日期格式为"2015-05-29 21:23:07"。此时,可以为:
<select id="getPlans" parameterType="hashMap" resultType="hashMap">
SELECT
`planId`, `type`, `planName`, `userId`, `nestId`, `userStatus`, `budgetStatus`, `budget`, `rule`, `isDelete`
FROM
`plan`
WHERE
isDelete=#{isDelete} AND nestId in
<foreach collection="nestIds" item="nestId" index="index"
open="(" close=")" separator=",">
#{nestId}
</foreach>
</select>
但是在另一个SQL中只能使用“*”,所以我只能查找解决方法了。经过查看官方文档和百度搜索。记得可以使用jdbc:mysql://localhost:3306/solr?characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useUnicode=true解决!所以我将Mysql JDBC Url参数表格附上,以便以后使用:
























本文出自 “梦朝思夕” 博客,请务必保留此出处http://qiangmzsx.blog.51cto.com/2052549/1656852
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: