[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);
//------------------------------------------------
%>

###############################################################

+ Recent posts