forked from halnigalni/DB_Team3_Phase4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addrole.jsp
78 lines (73 loc) · 2.2 KB
/
addrole.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
<%@ 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>Insert title here</title>
</head>
<body>
<form action = "ManagerAccount.jsp" method = "POST">
<%
String title_id = (String)session.getAttribute("title_id");
String manager_id = (String)session.getAttribute("manager_id");
String act_id = (String)session.getAttribute("act_id");
String serverIP = "localhost";
String strSID = "orcl";
String portNum = "1521";
String user = "university";
String pass = "comp322";
String url = "jdbc:oracle:thin:@"+serverIP+":"+portNum+":"+strSID;
String sql="";
ArrayList<Integer> id = new ArrayList<>();
Connection conn = null; // Connection object
Statement stmt = null; // Statement object
ResultSet rs;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection(url,user,pass);
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
sql = "SELECT Role_id FROM ROLED";
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);
}
int roleid = id.get(id.size()-1);
String age = request.getParameter("age");
String nationality = request.getParameter("nationality");
String rname = request.getParameter("name");
String isleading = request.getParameter("isleading");
if(isleading!=null)
{
isleading = "true";
}
else{
isleading = "false";
}
try {
sql = "INSERT INTO ROLED VALUES("+title_id+","+act_id+","+roleid+1+","+age+",'"+nationality+"','"
+rname+"','"+isleading+"')";
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 actor add </h3>");
session.setAttribute("manager_id", manager_id);
%>
<input type = "submit" value = "Go mypage">
</form>
</body>
</html>