[DB연결 include]
파일명:ssi.jsp
###############################################################
<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="java.sql.DriverManager"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.sql.ResultSet"%>
<%
request.setCharacterEncoding("utf-8");
//-------------------------------------------------------------
String url = "jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8";
String id = "root";
String pass = "1234";
String driver="org.gjt.mm.mysql.Driver";
Class.forName(driver);
Connection con = DriverManager.getConnection(url, id, pass);
//------------------------------------------------------------
%>
<%!
public void close(Connection con, PreparedStatement pstmt){
try{
if ( pstmt != null){ pstmt.close(); }
}catch(Exception e){}
try{
if ( con != null){ con.close(); }
}catch(Exception e){}
}//end
public void close(Connection con, PreparedStatement pstmt, ResultSet rs){
try{
if ( rs != null){ rs.close(); }
}catch(Exception e){}
try{
if ( pstmt != null){ pstmt.close(); }
}catch(Exception e){}
try{
if ( con != null){ con.close(); }
}catch(Exception e){}
}//end
%>
###############################################################
[성적테이블 수정]
파일명 : sungjukUpdate.jsp
###############################################################
<%@ page contentType="text/html; charset=utf-8" %>
<%@ include file="./ssi.jsp" %>
<%
//폼의 값 가져오기
String uname=request.getParameter("uname");
int kor=Integer.parseInt(request.getParameter("kor"));
int mat=Integer.parseInt(request.getParameter("eng"));
int eng=Integer.parseInt(request.getParameter("mat"));
int aver=(kor+mat+eng)/3;
String address=request.getParameter("address");
int sno = Integer.parseInt(request.getParameter("sno"));
//쿼리문 구성 및 실행
String sql = " UPDATE tb_sungjuk SET";
sql = sql + " uname = ?";
sql = sql + " ,kor = ?";
sql = sql + " ,eng = ?";
sql = sql + " ,mat = ?";
sql = sql + " ,aver = ?";
sql = sql + " ,address = ?";
sql = sql + " WHERE sno = ?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, uname);
pstmt.setInt(2, kor);
pstmt.setInt(3, eng);
pstmt.setInt(4, mat);
pstmt.setInt(5, aver);
pstmt.setString(6, address);
pstmt.setInt(7, sno);
int cnt = pstmt.executeUpdate(); //쿼리문 실행
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>sungjukUpdate.jsp</title>
</head>
<body>
<center>
<%
if (cnt == 1){
out.println("수정 성공!!");
}else{
out.println("수정 실패!!");
}
%>
<a href="./sungjukList.jsp">[성적목록]</a>
</center>
</body>
</html>
<%
//------------------------------------------------
close(con,pstmt);
//------------------------------------------------
%>
###############################################################
[성적테이블 삭제]
파일명 : sungjukDelete.jsp
###############################################################
<%@ page contentType="text/html; charset=utf-8" %>
<%@ include file="./ssi.jsp" %>
<%
//폼의 값 가져오기
int sno = Integer.parseInt(request.getParameter("sno"));
String sql = " DELETE FROM tb_sungjuk";
sql = sql + " WHERE sno = ?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, sno);
int cnt = pstmt.executeUpdate();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>sungjukDelete.jsp</title>
</head>
<body>
<center>
<%
if (cnt == 1){
out.println("삭제 성공!!");
}else{
out.println("삭제 실패!!");
}
%>
<a href="./sungjukList.jsp">[성적목록]</a>
</center>
</body>
</html>
<%
//------------------------------------------------
close(con,pstmt);
//------------------------------------------------
%>
###############################################################
'..열심히 공부하세.. > JSP' 카테고리의 다른 글
| [과제] 회원가입 (0) | 2012.02.15 |
|---|---|
| [09] Session 이용한 로그인 체크 (0) | 2012.02.15 |
| [07] 성적테이블 목록, 내용보기 (0) | 2012.02.13 |
| [06] Eclipse Helios 자바 개발 환경 툴 설치 (0) | 2012.02.12 |
| [05] 자바에서 MySQL 연동 (0) | 2012.02.10 |