Quantcast
Channel: 質問!ITmedia 新着質問(Java/253)
Viewing all articles
Browse latest Browse all 2439

javaの掲示板について

$
0
0
今現在パスワードを比較して一致していれば削除としたのですがjava.sql.SQLException: Can not issue data manipulation statements with executeQuery().というエラーがtomcatにでます。 サーブレットはこう書いています //削除 if(deleteMessage != null){ String deleteid = request.getParameter("id"); String deletepassword = request.getParameter("deletepassword"); String rspassword = dao.getPassword(deleteid); if (deletepassword.equals(rspassword)){ dao.deleteMessage(delete); success = "削除しました。"; request.setAttribute("success", success); } else{ errorpass = "パスワードが違います。"; request.setAttribute("errorpass", errorpass); } } 比較用のパスワードをデータベースから取り出すDAOはこうしています。 public int deleteMessage(String strid) throws Exception { Vector messageList = new Vector(); int i = 0; Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; try{ conn = this.getConnection(); String sql = "delete from MESSAGE_TABLE where ID = ? "; pstmt = conn.prepareStatement(sql); pstmt.setString(1, strid); rs = pstmt.executeUpdate(); } finally { this.close(rs); this.close(pstmt); this.close(conn); } return i; } public String getPassword(String id) throws Exception { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; String rspassword = null; try { String deleteid = null; conn = this.getConnection(); String sql = "SELECT * FROM MESSAGE_TABLE where ID = ? "; pstmt = conn.prepareStatement(sql); pstmt.setString(1, id); rs = pstmt.executeQuery(); if(rs.next()){ rspassword = rs.getString("PASSWORD"); } } finally { this.close(rs); this.close(pstmt); this.close(conn); } return rspassword; } データベースからパスワードがとれていないから起きているのだとは思うのですが、どのようにしたらとれるでしょうか? よろしくお願いします。

Viewing all articles
Browse latest Browse all 2439

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>