0
点赞
收藏
分享

微信扫一扫

java.sql.SQLException:Can not issue data manipulation statements with executeQuery()

青鸾惊鸿 2022-12-02 阅读 125


这里只贴出了错误提示的前部分

java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.Statement.checkForDml(Statement.java:302)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1148)
at com.lmm.loginDao.UserDao.addUser(UserDao.java:54)
at com.lmm.test.UserDaoTest.testAddUser(UserDaoTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)

在用JUnit5进行添加用户的单元测试时,遇到此错误,解决之后,记录一下解决方法

出现该错误的原因是进行insert,delete,update操作的时候使用了​​excecuteQuery()​​​方法,而不是excecuteUpdate()方法
网上总结如是说:
executeQuery()语句是用于产生单个结果集的语句,如select语句,
在什么情况下用executeQuery(),当你的数据库已经保存了数据后,要进行查询了。
executeUpdate():用于执行insert、update或者delete语句,返回值一个表示受影响的行数,即更新值
execute()运行语句,返回是否有结果集。


举报

相关推荐

0 条评论