-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.java
257 lines (251 loc) · 9.94 KB
/
Main.java
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import java.sql.*;
import java.util.*;
class Generate_Result
{
public void select_data(String roll)
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/student_result_management_system","root","admin");
Statement smt=con.createStatement();
ResultSet rs=smt.executeQuery("select * from student_db where student_roll="+roll);
System.out.println("Name\t\t\tRoll Number\tContact\t\tSubject 1\tSubject 2");
while(rs.next())
{
System.out.println(rs.getString(1)+"\t"+rs.getString(2)+"\t\t"+rs.getString(3)+"\t"+rs.getString(4)+"\t\t"+rs.getString(5));
}
con.close();
}
catch(Exception e)
{
System.out.println("Ehh Error :(");
}
}
}
class Login
{
public boolean user_login(String role, String user_name, String password)
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/student_result_management_system","root","admin");
Statement smt=con.createStatement();
ResultSet rs=smt.executeQuery("select * from user_db");
while(rs.next())
{
String s1=role+" "+user_name+" "+password;
String s2=rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3);
if(s1.equalsIgnoreCase(s2))
{
System.out.println("Login Successful");
return true;
}
}
con.close();
}
catch(Exception e)
{
System.out.println("Login Failed");
return false;
}
return false;
}
}
class Signup
{
public void new_user(String role, String user_name, String password)
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/student_result_management_system","root","admin");
Statement smt=con.createStatement();
ResultSet rs=smt.executeQuery("select * from user_db");
boolean f=true;
while(rs.next())
{
String s1=role+" "+user_name+" "+password;
String s2=rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3);
if(s1.equalsIgnoreCase(s2))
{
System.out.println("Credentials are not Unique");
f=false;
break;
}
}
if(f)
{
System.out.println("Sign_Up Successful");
int z=smt.executeUpdate("insert into user_db (user_role, user_name,user_password) values ('"+role+"','"+user_name+"','"+password+"')");
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Upload_marks
{
public void upload_marks_in_student_db(int roll, int marks, int subject)
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/student_result_management_system","root","admin");
Statement smt=con.createStatement();
if(subject==1)
{
int z=smt.executeUpdate("update student_db set student_subject1 = "+marks+" where student_roll = "+roll);
}
else if(subject==2)
{
int z=smt.executeUpdate("update student_db set student_subject2 = "+marks+" where student_roll = "+roll);
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Update_Student
{
public void new_student(String name, int roll, String contact)
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/student_result_management_system","root","admin");
Statement smt=con.createStatement();
String q="insert into student_db (student_name,student_roll,student_contact,student_subject1,student_subject2) values ('"+name+"',"+roll+",'"+contact+"',0,0)";
// System.out.println(q);
int z=smt.executeUpdate(q);
System.out.println("New Student Added");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
public class Main
{
public static void main(String args[])
{
String zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
Scanner sc=new Scanner(System.in);
int job_done=1;
while(job_done==1)
{
System.out.println("Press (1) to Login, Press (2) to SignUp and Press (3) to exit");
int choice=sc.nextInt();
if(choice==1)
{
System.out.print("Enter (1) if you are Admin, (2) for Teacher and (3) for Student: ");
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz=sc.nextLine();
String role=sc.nextLine();
System.out.print("Enter Your Username: ");
String username=sc.nextLine();
System.out.print("Enter Your Password: ");
String password=sc.nextLine();
Login obj=new Login();
boolean f=obj.user_login(role,username,password);
while(f)
{
if(role.equalsIgnoreCase("1"))
{
System.out.println("Press (1) to add New Student, (2) to Generate Result and (3) to LogOut");
choice=sc.nextInt();
if(choice==1)
{
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz=sc.nextLine();
System.out.print("Enter the Name: ");
String name=sc.nextLine();
System.out.print("Enter the Roll Number: ");
int rollno=sc.nextInt();
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz=sc.nextLine();
System.out.print("Enter the Student's Contact Number: ");
String contact=sc.nextLine();
Update_Student obj2=new Update_Student();
obj2.new_student(name,rollno,contact);
}
else if(choice==2)
{
System.out.print("Enter the Roll Number: ");
int rollno=sc.nextInt();
Generate_Result obj3=new Generate_Result();
obj3.select_data(""+rollno);
}
else if(choice==3)
{
f=false;
break;
}
}
else if(role.equalsIgnoreCase("2"))
{
System.out.println("Enter (1) to enter marks and (2) to exit");
choice=sc.nextInt();
if(choice==1)
{
System.out.print("Enter the Roll Number: ");
int roll=sc.nextInt();
System.out.print("Enter the Marks: ");
int marks=sc.nextInt();
System.out.print("Enter the Subject Number(1 or 2): ");
int subject=sc.nextInt();
// System.out.println(roll+" "+marks+" "+subject);
Upload_marks obj5=new Upload_marks();
obj5.upload_marks_in_student_db(roll,marks,subject);
}
else
{
f=false;
break;
}
}
else if(role.equalsIgnoreCase("3"))
{
System.out.println("Enter (1) to Generate Result and (2) to exit");
choice=sc.nextInt();
if(choice==1)
{
System.out.print("Enter the Roll Number: ");
int rollno=sc.nextInt();
Generate_Result obj4=new Generate_Result();
obj4.select_data(""+rollno);
}
else
{
f=false;
break;
}
}
}
}
else if(choice==2)
{
System.out.print("Enter (1) if you are Admin, (2) for Teacher and (3) for Student: ");
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz=sc.nextLine();
String role=sc.nextLine();
System.out.print("Enter Your Username: ");
String username=sc.nextLine();
System.out.print("Enter Your Password: ");
String password=sc.nextLine();
// System.out.println(role+" "+username+" "+password);
Signup obj4=new Signup();
obj4.new_user(role,username,password);
}
else if(choice==3)
{
break;
}
}
}
}