-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattendence.java
More file actions
111 lines (94 loc) · 3.07 KB
/
attendence.java
File metadata and controls
111 lines (94 loc) · 3.07 KB
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
package tools;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;
public class attendence {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i = 100;
while (i == 100) {
System.out.println("You Are A:- ");
System.out.println("1. Student");
System.out.println("2. Teacher");
System.out.println("3. Exit");
int option = sc.nextInt();
if (option == 1) {
System.out.println("Welcome Student ");
System.out.println("Enter your choice -");
System.out.println("1. View Your Attendence ");
System.out.println("2. Exit");
int t = sc.nextInt();
if (t == 1) {
try {
System.out.println("Enter your name: ");
String name = sc.next();
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/attendence", "root",
"root");
PreparedStatement p = con.prepareStatement("select * from att where name=?");
p.setString(1, name);
ResultSet r = p.executeQuery();
while (r.next()) {
System.out.println(r.getString(1) + "\t\t" + r.getString(2));
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (t == 2) {
break;
}
}
if (option == 2) {
System.out.println("Welcome Teacher Enter Username: ");
String tname = sc.next();
System.out.println("Enter Password: ");
String pass = sc.next();
if (tname.equals("Siddhant") && pass.equals("pass")) {
System.out.println("Enter your Choice - ");
System.out.println("1. View Student's Attendence");
System.out.println("2. Update Attendence");
System.out.println("3. Exit");
int t = sc.nextInt();
if (t == 1) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/attendence",
"root", "root");
PreparedStatement ps = con.prepareStatement("select * from att ");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
System.out.println(rs.getString(1) + "\t\t " + rs.getString(2));
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (t == 2) {
try {
System.out.println("Enter name of the student :");
String n = sc.next();
System.out.println("Enter attendence of the student :");
String at = sc.next();
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/attendence",
"root", "root");
PreparedStatement ps = con.prepareStatement("update att set attendence=? where name=? ");
ps.setString(1, at);
ps.setString(2, n);
ps.executeUpdate();
}
catch (Exception e) {
e.printStackTrace();
}
}
if (t == 3) {
break;
}
}
}
}
}
}