일단 테이블이 equipment이고 애트리뷰트 네개에 equip_id 기본키, equip_type 외래키야. 네개 전부 NOT NULL이고
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Equipment insert Page</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<% String Equip_type = request.getParameter("Equip_type"); %>
<br> 생성할 Equipment 를 입력하세요.<br>
<form name="form1" action="Equipment_insert_done.jsp" method="post">
<p> Equip_id: <input type="text" name="Equip_id"><br><br>
Equip_type: <input type="text" name="Equip_type"><br><br>
Maintenance_start: <input type="text" name="Maintenance_start"><br><br>
Maintenance_finish: <input type="text" name="Maintenance_finish"><br><br>
<input type="submit" name="formbutton1" value="보내기"> </p>
</form>
<p> </p>
</body>
</html>
이게 INSERT페이지고 여기서 입력한 자료를 밑에거에서 DB에 올리거든?
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>Insert Equipment done Page</title>
</head>
<body>
<%@ page import = "java.sql.*, java.util.*" %>
<%
String Equip_id=request.getParameter("Equip_id");
String Equip_type=request.getParameter("Equip_type");
String Maintenance_start=request.getParameter("Maintenance_start");
String Maintenance_finish=request.getParameter("Maintenance_finish");
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
PreparedStatement pstmt = null;
StringBuffer sql = new StringBuffer();
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbfinalproject", "root", "");
pstmt = conn.prepareStatement("insert into equipment (Equip_id, Equip_type, Maintenance_start, Maintenance_finish) values(?,?,?,?) ");
pstmt.setString(1, Equip_id);
pstmt.setString(2, Equip_type);
pstmt.setString(3, Maintenance_start);
pstmt.setString(4, Maintenance_finish);
pstmt.executeUpdate();
out.println("새 Equipment 가 입력되었습니다.");
} catch (SQLException e) {
out.println("데이터베이스 처리 문제 발생");
}
%>
<a href="Equipment_insert.jsp">계속 등록</a>
<a href="Equipment.jsp">Equipment 페이지로</a>
</body>
</html>
원래 내 예상으로는 네 애트리뷰트중 하나라도 없거나, 외래키 제약조건 어긋나면 다 예외조건으로 catch되길 바랬거든?
근데 예외조건이 외래키 제약조건 말곤 전부 쌩까... 심지어는 기본키에 아무것도 안써도 DB에 등록됨 -0-... 도와줘형들
SQL입센션으로 넣지말고 Exception e, 그리고 리절트 세트랑 커넥션 종료해주는 파이널 어딜로 도망갔어
오 ㄳ 근데 좀만 자세하게 설명해주면안될까 이해가안돼