-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadSQL.java
More file actions
127 lines (94 loc) · 4.54 KB
/
Copy pathReadSQL.java
File metadata and controls
127 lines (94 loc) · 4.54 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.sql.*;
public class ReadSQL{
private Connection conn;
public ReadSQL() throws SQLException{
//MUST UPDATE BELOW WITH YOUR CLASS LINK AND PASSWORD////////////////////
String url = "CLASS_LINK_HERE phpMyAdmin_SQL";
url += "PERSONAL_PASSWORD_FROM_CLASS";
//MUST UPDATE ABOVE WITH YOUR CLASS LINK AND PASSWORD/////////////////////
conn = DriverManager.getConnection(url);
}
public void readMemento() throws SQLException{
Statement stmt= conn.createStatement();
String query = "SELECT * FROM Memento";
ResultSet rs = stmt.executeQuery(query);
System.out.printf("%-21s %-11s %-8s%n",
"Name", "Yield", "LeaderID");
System.out.println("-----------------------------------------------");
while(rs.next()){
int LeaderID = rs.getInt("LeaderID");
String Name = rs.getString("Name");
String yield = rs.getString("yield");
System.out.printf("%-21s %-11s %7d%n",
Name, yield, LeaderID);
}
}
public void readBuilding() throws SQLException{
Statement stmt= conn.createStatement();
String query = "SELECT * FROM Building";
ResultSet rs = stmt.executeQuery(query);
System.out.printf("%-18s %-13s %-11s %-5s%n",
"Name", "Attribute", "Yield", "CivID");
System.out.println("---------------------------------------------------------");
while(rs.next()){
int CivID = rs.getInt("CivID");
String Name = rs.getString("Name");
String yield = rs.getString("yield");
String Attribute = rs.getString("Attribute");
System.out.printf("%-18s %-13s %-11s %5d%n",
Name, Attribute, yield, CivID);
}
}
public void readCivilization() throws SQLException{
Statement stmt= conn.createStatement();
String query = "SELECT * FROM Civilization";
ResultSet rs = stmt.executeQuery(query);
System.out.printf("%-6s %-13s %-13s %-13s %-11s%n",
"CivID", "Name", "Attribute", "Attribute2", "Yield");
System.out.println("---------------------------------------------------------");
while(rs.next()){
int CivID = rs.getInt("CivID");
String Name = rs.getString("Name");
String yield = rs.getString("yield");
String Attribute = rs.getString("Attribute");
String Attribute2 = rs.getString("Attribute2");
System.out.printf("%-6d %-13s %-13s %-13s %-11s%n",
CivID, Name, Attribute, Attribute2, yield);
}
}
public void readLeader() throws SQLException{
Statement stmt= conn.createStatement();
String query = "SELECT * FROM Leader";
ResultSet rs = stmt.executeQuery(query);
System.out.printf("%-9s %-23s %-13s %-13s %-11s %-11s%n",
"LeaderID", "Name", "Attribute", "Attribute2", "Yield", "Yield2");
System.out.println("----------------------------------------------------------------------------------");
while(rs.next()){
int LeaderID = rs.getInt("LeaderID");
String Name = rs.getString("Name");
String yield = rs.getString("yield");
String yield2 = rs.getString("yield2");
String Attribute = rs.getString("Attribute");
String Attribute2 = rs.getString("Attribute2");
System.out.printf("%-9d %-23s %-13s %-13s %-11s %-11s%n",
LeaderID, Name, Attribute, Attribute2, yield, yield2);
}
}
public void readView() throws SQLException{
Statement stmt= conn.createStatement();
String query = "SELECT * FROM OnlyScienceWithCombatBonus";
ResultSet rs = stmt.executeQuery(query);
System.out.printf("%-9s %-23s %-6s %-13s %-21s%n",
"LeaderID", "LeaderName","CivID", "CivName", "Memento");
System.out.println("----------------------------------------------------------------------------");
while(rs.next()){
int LeaderID = rs.getInt("LeaderID");
String LeaderName = rs.getString("LeaderName");
int CivID = rs.getInt("CivID");
String CivName = rs.getString("CivName");
String Memento = rs.getString("Memento");
System.out.printf("%-9d %-23s %-6d %-13s %-21s%n",
LeaderID, LeaderName, CivID, CivName, Memento);
}
}
}