- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.java
More file actions
Latest commit
46 lines (44 loc) · 1.74 KB
/
Copy pathDisplay.java
File metadata and controls
46 lines (44 loc) · 1.74 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
importjava.util.*;
importjava.sql.*;
classDisplay {
publicstaticvoidmain(Stringargs[]) {
try {
Stringnation, desg, n, d, nat;
intsal, y, emp, numrows = 0;
Scannerscan = newScanner(System.in);
Class.forName("com.mysql.cj.jdbc.Driver");
Connectioncon = DriverManager.getConnection("jdbc:mysql://localhost:3306/company", "root", "root");
Statementstm = con.createStatement();
System.out.println("Enter the nationality:");
nation = scan.nextLine();
System.out.println("Enter designation:");
desg = scan.nextLine();
Stringqry = "select * from employee";
ResultSetrs = stm.executeQuery(qry);
while (rs.next()) {
emp = rs.getInt(1);
n = rs.getString(2);
d = rs.getString(3);
nat = rs.getString(4);
y = rs.getInt(5);
sal = rs.getInt(6);
if (d.equalsIgnoreCase(desg) == true && nat.equalsIgnoreCase(nation) == true) {
numrows++;
System.out.println(emp + "\t" + n + "\t" + d + "\t" + nat + "\t" + y + "\t" + sal);
}
}
if (numrows > 0) {
System.out.println(numrows + "rows retrieved");
} else {
System.out.println("Not Found");
}
con.close();
stm.close();
rs.close();
} catch (ClassNotFoundExceptione) {
System.out.println("Caught exception:" + e);
} catch (SQLExceptione) {
System.out.println("Caught exception:" + e);
}
}
}