%@ 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 content = request.getParameter("content");
// 디버깅 용
System.out.println(no);
System.out.println(name);
System.out.println(content);
// 오라클에 접속하기 위해서는 드라이버를 로드해야 한다.
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 message(no,name,content) values(?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
// ?(물음표)룔 채워줘야 함.
pstmt.setInt(1, no); // 번호
pstmt.setNString(2, name); // 이름
pstmt.setNString(3, content); // 메시지
int result = pstmt.executeUpdate();
System.out.println(result +"개가 입력되었습니다.");
pstmt.close();
conn.close();
response.sendRedirect("list.jsp");
}
catch(Exception e){}
finally{}
%>