인생코딩

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록
Web Programming/JSP

[JSP]java.sql.SQLException:No value specified for parameter 해결방법

2017. 5. 10. 15:01

java.sql.SQLException:No value specified for parameter ~~ 


해당 에러는 PreparedStatement 사용 시 나오는

또한, 헷갈리고 착각해서 자주 나오는 고치기 쉬운(?) 에러다


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<%    
    String userid = request.getParameter("id");
    String userpw = request.getParameter("pw");
 
    String query = "SELECT id, name, birth FROM members WHERE id=? AND passwd=?";
    
    PreparedStatement pstmt = dbconn.preparedStatement(query);
    pstmt.setString(1, userid);
    
    ResultSet rs = pstmt.executeQuery();
 
    if(rs.next()){
        // 이하 공백
    }
%>
Colored by Color Scripter
cs


저렇게 쿼리에선 인자를 두 개나 받고 있으면서 하나만 넣어주면 생기는 에러다.


저런 경우에는 

pstmt.setString(2, userpw);

와 같이 두 번째 인자에도 값을 넣어줘야한다.


또한,


java.sql.SQLException:No value specified for parameter 2

두 번째 인자 값이므로, parameter 2 라고 에러가 발생한다.

저작자표시 (새창열림)

'Web Programming > JSP' 카테고리의 다른 글

[JSP]PSQLException: ResultSet not positioned properly, perhaps you need to call next 해결방법  (0) 2017.05.11
southouse
인생은 Birth(B)와 Dead(D)사이의 Coding(C)이다.
Designed By 정상우.

티스토리툴바