mybatis 用 update 出错大神来看看

braveboyny 2019-05-03 09:08:12

这是错误信息

HTTP Status 500 – Internal Server Error

--------------------------------------------------------------------------------

Type Exception Report

Message Request processing failed; nested exception is org.springframework.dao.RecoverableDataAccessException:

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.RecoverableDataAccessException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 2,329 milliseconds ago. The last packet sent successfully to the server was 2,328 milliseconds ago.
### The error may involve org.neolyao.stu.dao.GradeDAO.updateGrade-Inline
### The error occurred while setting parameters
### SQL: update grade set grades=? where st_id=? and c_id=?
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 2,329 milliseconds ago. The last packet sent successfully to the server was 2,328 milliseconds ago.
; SQL []; Communications link failure

The last packet successfully received from the server was 2,329 milliseconds ago. The last packet sent successfully to the server was 2,328 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 2,329 milliseconds ago. The last packet sent successfully to the server was 2,328 milliseconds ago.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause

org.springframework.dao.RecoverableDataAccessException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


这是mapper里update

<update id="updateGrade" parameterType="org.neolyao.stu.bean.Grade">
update grade
set grades=#{grade}
where st_id=#{st_id} and c_id=#{c_id}
</update>


每次点击更新之后 连数据库都停止运行了 ,这是怎么回事啊
...全文
2748 45 打赏 收藏 转发到动态 举报
写回复
用AI写文章
45 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ezirio 2019-05-10
  • 打赏
  • 举报
回复
感觉像是parametertype的问题,请问你的grade参数是啥类型
braveboyny 2019-05-09
  • 打赏
  • 举报
回复
引用 49 楼 Timor__ 的回复:
[quote=引用 47 楼 braveboyny 的回复:] [quote=引用 40 楼 Timor__ 的回复:] 一般实体类属性最好要跟表的字段一样
我终于找到原因了, 我的表名 和 表的一个列名相同了都是grade,我把表名改了就对了。谢了兄弟[/quote] 没事[/quote] 前天去面试,被问3问题都没答起,1.问我啥是同步和异步2.拦截器和过滤器的区别3,finallize啥时候被调用
Timor__ 2019-05-09
  • 打赏
  • 举报
回复
引用 52 楼 braveboyny 的回复:
[quote=引用 49 楼 Timor__ 的回复:] [quote=引用 47 楼 braveboyny 的回复:] [quote=引用 40 楼 Timor__ 的回复:] 一般实体类属性最好要跟表的字段一样
我终于找到原因了, 我的表名 和 表的一个列名相同了都是grade,我把表名改了就对了。谢了兄弟[/quote] 没事[/quote] 前天去面试,被问3问题都没答起,1.问我啥是同步和异步2.拦截器和过滤器的区别3,finallize啥时候被调用[/quote]
braveboyny 2019-05-07
  • 打赏
  • 举报
回复
今天去面试被问2问题都没答出来,1.是什么是同步和异步2.拦截器和过滤器区别
weixin_39055028 2019-05-06
  • 打赏
  • 举报
回复
那我是不是得100分
Timor__ 2019-05-06
  • 打赏
  • 举报
回复
引用 47 楼 braveboyny 的回复:
[quote=引用 40 楼 Timor__ 的回复:] 一般实体类属性最好要跟表的字段一样
我终于找到原因了, 我的表名 和 表的一个列名相同了都是grade,我把表名改了就对了。谢了兄弟[/quote] 没事
迁尘 2019-05-05
  • 打赏
  • 举报
回复
楼主你是不是用4.0的连接驱动?如果其他方法试不得,我建议你换5.1的连接驱动吧。具体很难看出有什么毛病啊
我爱吃地瓜 2019-05-05
  • 打赏
  • 举报
回复
把参数#{grade}换成 #{0},#{st_id}换成#{1},c_id换成#{2} 或者在dao成方法参数换成@Param("grades") String grade。。。。。
Timor__ 2019-05-05
  • 打赏
  • 举报
回复
一般实体类属性最好要跟表的字段一样
Timor__ 2019-05-05
  • 打赏
  • 举报
回复
我今天才发现,你这两个怎么都不一样,你实体类是怎么写的
braveboyny 2019-05-05
  • 打赏
  • 举报
回复
引用 37 楼 weixin_39055028 的回复:
[quote=引用 2 楼 braveboyny的回复:][quote=引用 1 楼 Timor__ 的回复:] 你加一下参数类型,模仿我这个试一下

	<delete id="deleteGradeById"  parameterType="org.neolyao.stu.bean.Grade" >
		delete from grade where st_id=#{st_id} and c_id=#{c_id}
	</delete>
	<update id="updateGrade" parameterType="org.neolyao.stu.bean.Grade">
		update grade 
		set grades=#{grade,jdbcType=TINYINT}
		where st_id=#{st_id,jdbcType=VARCHAR} and c_id=#{c_id,jdbcType=VARCHAR}
	</update>
改成这样了,还是一样的,我试了下delete能正常执行[/quote] 为什么你set grades传入的值名字,和数据库的表名一致?这样你的sql会没有问题・_・?[/quote] 我终于找到原因了, 我的表名 和 表的一个列名相同了都是grade,我把表名改了就对了。谢了兄弟
braveboyny 2019-05-05
  • 打赏
  • 举报
回复
引用 40 楼 Timor__ 的回复:
一般实体类属性最好要跟表的字段一样
我终于找到原因了, 我的表名 和 表的一个列名相同了都是grade,我把表名改了就对了。谢了兄弟
Uranus.X 2019-05-05
  • 打赏
  • 举报
回复
能贴一下实体类代码么?看一下参数和字段对不对的上
nayi_224 2019-05-05
  • 打赏
  • 举报
回复
本地电脑和mysql服务先重启一下看看
狂舖 2019-05-05
  • 打赏
  • 举报
回复
试下这样写呢 url: jdbc:mysql://127.0.0.1:3306/数据库?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
老王就是我 2019-05-05
  • 打赏
  • 举报
回复
看一下参数有没传进去
程序员@小白 2019-05-04
  • 打赏
  • 举报
回复
先把SQL移到数据库执行一下看看是不是SQL的错误呗
a2956785182 2019-05-04
  • 打赏
  • 举报
回复
.........看不懂
weixin_39055028 2019-05-04
  • 打赏
  • 举报
回复
引用 2 楼 braveboyny的回复:
[quote=引用 1 楼 Timor__ 的回复:] 你加一下参数类型,模仿我这个试一下

	<delete id="deleteGradeById"  parameterType="org.neolyao.stu.bean.Grade" >
		delete from grade where st_id=#{st_id} and c_id=#{c_id}
	</delete>
	<update id="updateGrade" parameterType="org.neolyao.stu.bean.Grade">
		update grade 
		set grades=#{grade,jdbcType=TINYINT}
		where st_id=#{st_id,jdbcType=VARCHAR} and c_id=#{c_id,jdbcType=VARCHAR}
	</update>
改成这样了,还是一样的,我试了下delete能正常执行[/quote] 为什么你set grades传入的值名字,和数据库的表名一致?这样你的sql会没有问题・_・?
笔记_blog 2019-05-04
  • 打赏
  • 举报
回复
这条sql可以执行成功?在控制台上?然后这是链接超时的问题,,,,或许不是sql得问题,,,
加载更多回复(25)

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧