java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:501)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2150)
at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:107)
at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:107)
at com.peace.dao.impl.MsgDaoImp.insertMsg(MsgDaoImp.java:90)
at com.peace.service.impl.MsgServiceImpl.add(MsgServiceImpl.java:22)
at com.peace.servlet.InsertServlet.service(InsertServlet.java:42)
...
错误原因:

解决方法:
//增
PreparedStatement pst = null;
pst = conn.prepareStatement(sql);
pst.executeQuery();
/* executeQuery():使用情况 => 新增、修改、删除
* executeQuery():使用情况 => 查
*/

解决MySQL executeQuery异常
本文详细解析了在使用Java操作MySQL数据库时,遇到的Cannot issue data manipulation statements with executeQuery()异常的原因及解决方法。强调了executeQuery()方法适用于查询操作,而执行增删改等数据操纵语句应使用executeUpdate()。
2万+

被折叠的 条评论
为什么被折叠?



