1. 程式人生 > >java.sql.SQLException: Can not issue data manipulation statements with executeQuery().

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

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():使用情況 => 查
*/

在這裡插入圖片描述