-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJDBCTesting.java
More file actions
87 lines (59 loc) · 1.89 KB
/
JDBCTesting.java
File metadata and controls
87 lines (59 loc) · 1.89 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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
public class JDBCTesting {
public static void main(String[] args) throws Exception {
String dbURL = "jdbc:derby://localhost:1527/rpsdb;user=guest;password=password";
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection conn = DriverManager.getConnection(dbURL);
Statement stmt = conn.createStatement();
ResultSet results = stmt.executeQuery("select * from GAMESUMMARY");
ResultSetMetaData rsmd = results.getMetaData();
int numberCols = rsmd.getColumnCount();
for (int i = 1; i <= numberCols - 1; i++) {
System.out.print(rsmd.getColumnLabel(i) + "\t\t");
}
System.out.println("\n-------------------------------------------------------");
while (results.next()) {
GameSummary gameSummary = new GameSummary();
gameSummary.id = results.getInt(1);
gameSummary.client = results.getString(2);
gameSummary.server = results.getString(3);
gameSummary.result = results.getString(4);
System.out.println(gameSummary.id + "\t\t" + gameSummary.client + "\t\t" + gameSummary.server + "\t\t" + gameSummary.result);
}
results.close();
stmt.close();
}
}
/*
ID CLIENT SERVER RESULT
---------------------------------------
1 ROCK ROCK TIE
2 PAPER ROCK TIE
3 ROCK ROCK TIE
4 Rock Paper Loss
5 Rock Paper Loss
*/
/*
ID CLIENT SERVER RESULT
---------------------------------------
1 ROCK ROCK TIE
2 PAPER ROCK TIE
3 ROCK ROCK TIE
4 Rock Paper Loss
5 Rock Paper Loss
*/
class GameSummary {
public long id;
public String toString() {
return "GameSummary [id=" + id + ", client=" + client + ", server=" + server + ", result=" + result + ", date="
+ date + "]";
}
public String client;
public String server;
public String result;
public java.util.Date date;
}