getConnection : connection 객체 생성 con = DriverManager.getConnection(url,id,pw); System.out.println("연결 성공..."); } catch (Exception e) { System.out.println("연결 실패..."); e.printStackTrace(); } return con; } // getConnection() end public void DeletArticle() { Scanner sc = new Scanner(System.in); System.out.print("삭제할 이름 입력 > "); String del_name = sc.nex"> getConnection : connection 객체 생성 con = DriverManager.getConnection(url,id,pw); System.out.println("연결 성공..."); } catch (Exception e) { System.out.println("연결 실패..."); e.printStackTrace(); } return con; } // getConnection() end public void DeletArticle() { Scanner sc = new Scanner(System.in); System.out.print("삭제할 이름 입력 > "); String del_name = sc.nex"> getConnection : connection 객체 생성 con = DriverManager.getConnection(url,id,pw); System.out.println("연결 성공..."); } catch (Exception e) { System.out.println("연결 실패..."); e.printStackTrace(); } return con; } // getConnection() end public void DeletArticle() { Scanner sc = new Scanner(System.in); System.out.print("삭제할 이름 입력 > "); String del_name = sc.nex">
package ch05_delete;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

class delete {
	// 연결 정보
	private String url = "jdbc:oracle:thin:@localhost:1521:xe";
	private String id = "DBTEST";
	private String pw = "a1234";
	
	public delete() {
		// jdbc 드라이버 할당.
		try {
			Class.forName("oracle.jdbc.OracleDriver");
			System.out.println("로딩 성공...");
		} catch (Exception e) {
			System.out.println("로딩 실패...");
			e.printStackTrace();
		}
	} // delete() end
	
	public Connection getConnection() {
		Connection con = null;
		try {
			// DB연결 객체 생성 -> getConnection : connection 객체 생성
			con = DriverManager.getConnection(url,id,pw);
			System.out.println("연결 성공...");
		} catch (Exception e) {
			System.out.println("연결 실패...");
			e.printStackTrace();
		}
		return con;
	} // getConnection() end
	
	
	public void DeletArticle() {
		Scanner sc = new Scanner(System.in);
		System.out.print("삭제할 이름 입력 > ");
		String del_name = sc.next();
		
		Connection con = null;
		PreparedStatement pstmt = null;
		int res = 0;
		try {
			String sql="delete from member where name=? ";
			con=getConnection();
			pstmt=con.prepareStatement(sql);
			pstmt.setString(1, del_name);
			res=pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(pstmt!=null) pstmt.close();
				if(con!=null) con.close();
				if(sc!=null) sc.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		System.out.println(res + "행 삭제 완료...");
		
	}
	
}

public class DeleteTest {
	public static void main(String[] args) {
		delete del = new delete();
		del.DeletArticle();
	}
}