%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
Insert title here
<%
try
{
int no = Integer.parseInt(request.getParameter("no"));
String name = request.getParameter("name");
String phonenum = request.getParameter("phonenum");
String memo = request.getParameter("memo");
// 디버깅 용
System.out.println(no);
System.out.println(name);
System.out.println(phonenum);
System.out.println(memo);
// 오라클에 접속하기 위해서는 드라이버를 로드해야 한다.
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe",
"HR",
"1234");
if (conn == null) {System.out.println("DB접속에 실패");}
else {System.out.println("DB접속 성공");}
String sql = "insert into phonebook(no,name,phonenum,memo) values(?,?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
// ?(물음표)룔 채워줘야 함.
pstmt.setInt(1, no); // 번호
pstmt.setNString(2, name); // 이름
pstmt.setNString(3, phonenum); // 전하번호
pstmt.setNString(4, memo); // 메모
int result = pstmt.executeUpdate();
System.out.println(result +"개가 입력되었습니다.");
pstmt.close();
conn.close();
response.sendRedirect("list.jsp");
}
catch(Exception e){}
finally{}
%>