-
Notifications
You must be signed in to change notification settings - Fork 1
/
movieadding.jsp
146 lines (136 loc) · 4.11 KB
/
movieadding.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page language = "java" import ="java.text.*, java.sql.*"%>
<%@ page language = "java" import = "java.util.ArrayList,javax.swing.JButton,javax.swing.ButtonGroup " %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Adding</title>
</head>
<body>
<form action = ManagerAccount.jsp method = "POST">
<%
int title_id = 0;
String manager_id ="0lHyaPqJGF";
//(String)session.getAttribute("manager_id");
String title = request.getParameter("title");
String startyear= request.getParameter("startyear");
String endyear= request.getParameter("endyear");
String runtime=request.getParameter("runtime");
String ost=request.getParameter("ost");
String director=request.getParameter("director");
String writer=request.getParameter("writer");
String audience=request.getParameter("audience");
String hasclip=request.getParameter("hasclip");
String is_adult=request.getParameter("is_adult");
String type=request.getParameter("type");
String [] getgenre = request.getParameterValues("genre");
String [] getversion = request.getParameterValues("version");
ArrayList<Integer> genre = new ArrayList<>();
ArrayList<Integer> version = new ArrayList<>();
ArrayList<Integer> id = new ArrayList<>(); // 현재 디비에 저장된 movie의 id 개수를 구하기 위함
String serverIP = "localhost";
String strSID = "orcl";
String portNum = "1521";
String user = "university";
String pass = "comp322";
String url = "jdbc:oracle:thin:@"+serverIP+":"+portNum+":"+strSID;
Connection conn = null; // Connection object
Statement stmt = null; // Statement object
ResultSet rs;
String sql = "";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection(url,user,pass);
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
sql = "SELECT title_id FROM MOVIE";
rs = stmt.executeQuery(sql);
while(rs.next())
{
id.add(rs.getInt(1));
}
rs.close();
}catch(SQLException ex)
{
System.err.println("sql error = "+ex.getMessage());
System.exit(1);
}
title_id = id.get(id.size()-1)+1;
if(is_adult == null)
{
is_adult = "false";
}
else
{
is_adult= "true";
}
if(hasclip==null)
{
hasclip = "false";
}
else{
hasclip = "true";
}
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
if(endyear.equals(""))
{
sql = "INSERT INTO MOVIE VALUES ("+title_id+", '"+title+"','"+is_adult+"',"+runtime
+",'"+ost+"',"+audience+",'"+hasclip+"','"+director+"','"+writer
+"',TO_DATE('"+startyear+"','mm-dd-yyyy'),NULL,'"+type+"','"
+manager_id+"')";
System.out.println(sql);
}
else
{
sql = "INSERT INTO MOVIE VALUES ("+title_id+", '"+title+"','"+is_adult+"',"+runtime
+",'"+ost+"',"+audience+",'"+hasclip+"','"+director+"','"+writer
+"',TO_DATE('"+startyear+"','mm-dd-yyyy'),TO_DATE('"+endyear+"','mm-dd-yyyy'),'"+type+"','"
+manager_id+"')";
System.out.println(sql);
}
//System.out.println(sql);
int res = stmt.executeUpdate(sql);
conn.commit();
}catch(SQLException ex2) {
System.err.println("sql error = "+ex2.getMessage());
System.exit(1);
}
for(int i =0;i<getgenre.length;i++)
{
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
sql = "INSERT INTO HAS_GENRE VALUES("+title_id+","+getgenre[i]+")";
System.out.println(sql);
int res = stmt.executeUpdate(sql);
conn.commit();
}catch(SQLException ex2) {
System.err.println("sql error = "+ex2.getMessage());
System.exit(1);
}
}
for(int i =0;i<getversion.length;i++)
{
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
sql = "INSERT INTO HAS_GENRE VALUES("+title_id+","+getversion[i]+")";
System.out.println(sql);
int res = stmt.executeUpdate(sql);
conn.commit();
}catch(SQLException ex2) {
System.err.println("sql error = "+ex2.getMessage());
System.exit(1);
}
}
out.println("<h3>complete add new movie</h3>");
session.setAttribute("manager_id",manager_id);
%>
<input type = "submit" value = "Go mypage">
</form>
</body>
</html>