마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

jsp PreparedStatement사용방법 좀

0 추천

jsp Prepared Dtatement 사용할려고 합니다.

지금은 jsp와 db는 오라클을 쓰고있습니다. 가용방법좀 알려주세요

<%@page import="com.mysql.jdbc.PreparedStatement"%>
<%@page import="com.sun.xml.internal.bind.v2.schemagen.xmlschema.List"%>
<%@ page import="java.sql.*" language="java"
 contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ page import="java.io.*"%>

<%!boolean isIdExist = false;%>

<%
 // 요청시 한글 처리

 request.setCharacterEncoding("UTF-8");

 // 요청시 한글처리

 response.setContentType("text/html;charset=UTF-8");

 // 요청한 곳으로부터 파라미터 받기

 String u_id = request.getParameter("id");
 String u_pwd = request.getParameter("pwd");
 Connection con = null;
 Statement st = null;
 PreparedStatement pstmt = null;
 ResultSet rs = null;
 try {

  Class.forName("oracle.jdbc.driver.OracleDriver");
  String url = "jdbc:oracle:thin:@211.227.000.000:.0001521:orcl";
  String db_id = "scott";
  String db_pw = "qwe123";
  con = DriverManager.getConnection(url, db_id, db_pw);
  st = con.createStatement();
  String sql = "select*from member1";
  rs = st.executeQuery(sql);
  while (rs.next()) {
   String id = rs.getString("id");
   String pwd = rs.getString("pwd");
   String name = rs.getString("name");
   String phone = rs.getString("reg_date");
   String msg = "";

   if (id.equals(u_id)) {
    isIdExist = true;

    if (pwd.equals(u_pwd)) {
     out.println(name + "님 로그인되었습니다. 환영합니다.");

     sql = "update member2 set day = '1' where id ='?'";
     //pstmt = con.createStatement(sql);이쪽부분입니다.
 
    pstmt.setString(1, u_id);

    } else {
     out.println("비밀번호가 틀렸습니다.");
    }
   }
  }

  if (!isIdExist) {
   out.println("아이디가 틀렸습니다.");
  }
 } catch (ClassNotFoundException e) {
  e.printStackTrace();
 } catch (SQLException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 try {
  if (rs != null)
   rs.close();
  if (st != null)
   st.close();
  if (con != null)
   con.close();
  if(pstmt != null)
   pstmt.close();
 } catch (SQLException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
%>


 

ㄴㅇ

주석처리한 부분 pstmt = con.createStatement(sql); 이렇게 쓰는건지 알고 싶습니다.

이렇게 쓰면 The method createStatement() in the type Connection is not applicable for the arguments (String) 이런 오류가 뜸니다 확인 방법 좀 사용방버좀 ㅜㅜ

익명사용자 님이 2013년 8월 15일 질문
2013년 8월 15일 수정

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...