Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 이클립스
- html
- Eclipse
- 파일이동버튼
- 필드
- emmet
- arraylist
- 버튼페이지이동
- list
- Collection
- Git이해하기
- java입문
- javascript
- 점프 투 파이썬
- java
- cmd
- java기초
- object
- 맨땅에 해딩
- form
- 컬렉션프레임워크
- Git알아보기
- 데이터베이스연동
- 오버라이딩
- 배열
- 기본코드
- CSS
- js
- jdbc
- MySQL
Archives
- Today
- Total
단단히
Statement.executeQuery() cannot issue statements that do not produce result sets. 본문
Java/오류
Statement.executeQuery() cannot issue statements that do not produce result sets.
이게아닌데 2022. 9. 23. 11:12
Statement.executeQuery() cannot issue statements that do not produce result sets.
Java.sql.SQLException 오류가 발생했다.
오류 메시지
Statement.executeQuery()는 결과 집합을 생성하지 않는 문을 실행할 수 없습니다.
원인을 찾아보았다.
DB와 연동 시 Selete 문이 아닌 다른 쿼리를 사용할 때는 executeQuery() 문을 사용할 수 없다.
<%
String uid = request.getParameter("uid");
Connection objConn = null;
Statement objStmt = null;
ResultSet objRS = null;
String sql = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/데이터베이스명?";
url += "useSSL=false&";
url += "useUnicode=true&";
url += "characterEncoding=UTF8&";
url += "serverTimezone=UTC";
String user = "root";
String password = "1234";
objConn = DriverManager.getConnection(url, user, password);
//out.print("DBConnection OK!!!"); 찍어보기
sql = "delete from member where uid='"+uid+"'";
objStmt = objConn.createStatement();
objStmt.executeQuery(sql);
response.sendRedirect("/ ... /index.jsp");
} catch (ClassNotFoundException cnfe) {
out.print("cnfe : " + cnfe.getMessage());
} catch (SQLException sqle) {
out.print("sqle : " + sqle.getMessage());
}
%>
나는 회원을 삭제하기 위해 Delete문을 호출했는데,
이때는 executeUpdate() 문이나 execute() 문을 사용해야 한다.
나는 execute()를 사용했다.
<%
String uid = request.getParameter("uid");
Connection objConn = null;
Statement objStmt = null;
ResultSet objRS = null;
String sql = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/QD06_Member?";
url += "useSSL=false&";
url += "useUnicode=true&";
url += "characterEncoding=UTF8&";
url += "serverTimezone=UTC";
String user = "root";
String password = "1234";
objConn = DriverManager.getConnection(url, user, password);
//out.print("DBConnection OK!!!");
sql = "delete from member where uid='"+uid+"'";
objStmt = objConn.createStatement();
objStmt.execute(sql);
response.sendRedirect("/member/index.jsp");
} catch (ClassNotFoundException cnfe) {
out.print("cnfe : " + cnfe.getMessage());
} catch (SQLException sqle) {
out.print("sqle : " + sqle.getMessage());
}
%>
이때 삭제만 하고 바로 다음 페이지로 넘어갈 것이기 때문에
반환 값이 필요 없다고 생각했다.
Statement.executeQuery()는 ResultSet을 반환하는 메서드이며 Select에서 사용한다. execute() 문
Create, alter, delete, update, insert.. 에서 사용하는 쿼리는 executeUpdate() 문이다.
execute() 문은 boolean(F/T)를 반환하며 executeQuery(), executeUpdate() 모두 사용할 수 있다.
'Java > 오류' 카테고리의 다른 글
Cannot make a static reference to the non-static method mtd_JDBC() from the type DAO (0) | 2022.09.21 |
---|
Comments