-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintTables.java
112 lines (83 loc) · 4.69 KB
/
PrintTables.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
package AIM;
import java.sql.*;
public class PrintTables {
public ResultSet JDBC(String query, String database_name, String password) {
Connection c = null;
try {
c = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + database_name + "", "root", password);
} catch (SQLException e) {
throw new RuntimeException(e);
}
Statement s = null;
try {
s = c.createStatement();
} catch (SQLException e) {
throw new RuntimeException(e);
}
ResultSet r;
try {
r = s.executeQuery(query);
} catch (SQLException e) {
throw new RuntimeException(e);
}
return r;
}
public void P_Tables() throws SQLException {
PrintTables Tables = new PrintTables();
ResultSet r = Tables.JDBC("SELECT * FROM Authentication", "pavan", "Pavan@161103");
System.out.println(" ID's\t\t\t\tPassword's");
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
while (r.next()) {
System.out.println(r.getString(1) + "\t\t\t\t" + r.getString(2));
}
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
r = Tables.JDBC("SELECT * FROM bomb", "pavan", "Pavan@161103");
System.out.println("\tBombs\t\t\t\t Number of bombs");
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
while (r.next()) {
System.out.println(r.getString(1) + "\t\t\t\t" + r.getInt(2));
}
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
r = Tables.JDBC("SELECT * FROM Food ", "pavan", "Pavan@161103");
System.out.format("%15s %15s\n", "Food", "Quantity");
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
while (r.next()) {
System.out.format("%15s %10d\n", r.getString(1), r.getInt(2));
}
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
r = Tables.JDBC("SELECT * FROM Clothes ", "pavan", "Pavan@161103");
System.out.format("%15s %20s\n", "Clothes", "Quantity");
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
while (r.next()) {
System.out.format("%20s %10d\n", r.getString(1), r.getInt(2));
}
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
r = Tables.JDBC("SELECT * FROM Ammunitions ", "pavan", "Pavan@161103");
System.out.format("%15s %20s\n", "Gun", "Quantity");
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
while (r.next()) {
System.out.format("%20s %15d\n", r.getString(1), r.getInt(2));
}
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
System.out.println(
"-------------------------------------------------------------------------------------------------------------------------");
}
}