1.StudenMain -> 2.StudentInsertForm -> 3.StudentInsert ->학생 추가 class !
<%@ page import = "" %>을 이용하여, import 해야되는것을 연결
<%@ page import ="java.sql.*"%>
<%@ page import ="com.test.*"%>
<%
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name");
String tel = request.getParameter("tel");
request -> 값을 수신하는 명령어! (즉, 입력받은 값을 불러오는 역할)
Connection conn = null;
PreparedStatement pstmt = null;
try{
conn = DBConn.getConnection();
String sql = String.format("INSERT INTO student (sid, name, tel) VALUES((select NVL(max(sid),0)+1 from STUDENT), ?, ?)");
-> 학생 추가 구문이기때문에 Insert 구문을 적어준다
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,name);
pstmt.setString(2,tel);
-> 바인딩 부분이 2개!
pstmt.executeUpdate();
}catch(Exception e){
e.printTrackTrace();
}finally{
try{
if(pstmt != null){
pstmt.close();
}
}catch(Exception e){
}
DBConn.close();
}
response.sendRedirect("studentMain.jsp");
->입력이 완료된후, 나타나는 페이지를 강제적으로 지정된 페이지가 나타나도록 해준다
%>
'JSP' 카테고리의 다른 글
02일차_데이터송수신 (0) | 2015.06.22 |
---|---|
01일차_JSP실행구조, 스크립트요소 (0) | 2015.06.22 |
StudentInsertForm (1) | 2015.05.15 |
StudentMain (1) | 2015.05.15 |
Insert작성방법 (0) | 2015.05.15 |