-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjdbc2.java
119 lines (97 loc) · 4.6 KB
/
jdbc2.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
113
114
115
116
117
118
119
/*H***********************************************************************
* FILENAME : jdbc2.java
*
* DESCRIPTION :
* Uses jdbc to produce different views of the airline database
*
* NOTES :
* For the user, password, db, and jdbc variables,
* you must enter your own personal information.
*
* Copyright 2018, Jacob Wilkins. All rights reserved.
*
* AUTHOR : Jacob Wilkins START DATE : 22 Apr 18
*
*H*/
import java.sql.*;
import java.util.Scanner;
final class mysql {
final static String user = "username";
final static String password = "password";
final static String db = "databaseName";
final static String jdbc = "connectionURL" + db + "?user=" + user + "&password=" + password;
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection(jdbc);
boolean bool = true;
Scanner in = new Scanner(System.in);
int a, ID, Seq;
String name = "", dateHired = "", FLNO = "", FDate = "";
while (bool) {
System.out.println("1. Check if Pilot is busy on a certain day and show the pilot assignments for this day");
System.out.println("2. Assign a Pilot to a flight leg instance");
System.out.println("3. Add a Pilot");
System.out.println("4. Quit");
System.out.print("Enter a Number: ");
a = in .nextInt();
System.out.print("\n");
int count = 0;
ResultSet rs = null;
Statement st = null;
Statement stmt = null;
switch (a) {
case 1:
System.out.print("Enter a name: ");
name = in.next();
System.out.print("Enter a date: ");
FDate = in.next();
System.out.print("\n");
count = 0;
st = con.createStatement();
rs = st.executeQuery("SELECT p.ID, p.Name, fli.FLNO, fl.FromA, fl.ToA, fli.FDate FROM FlightLegInstance fli, FlightLeg fl, Pilot p WHERE fli.Pilot = p.ID AND fl.Seq = fli.Seq AND fl.FLNO = fli.FLNO AND p.Name = '" + name + "' AND fli.FDate = '" + FDate + "'");
System.out.println(" \tID\tName\tFLNO\tFromA\tToA\tFDate");
System.out.println(" ---------------------------------------------------");
while(rs.next()) {
count++;
String str = rs.getString("p.ID") + "\t" + rs.getString("p.Name") + "\t" + rs.getString("fli.FLNO") + "\t" + rs.getString("fl.FromA") + "\t" + rs.getString("fl.ToA") + "\t" + rs.getString("fli.FDate");
System.out.println(count + ".\t" + str);
}
if (count > 0) {
System.out.println("\n" + name + " is busy this day!\n");
} else {
System.out.println("\n" + name + " is free this day!\n");
}
st.close();
break;
case 2:
System.out.print("Enter new Pilot ID: ");
ID = in.nextInt();
System.out.print("Enter FLNO: ");
FLNO = in.next();
System.out.print("Enter Seq: ");
Seq = in.nextInt();
System.out.print("Enter Flight Date: ");
FDate = in.next();
st = con.createStatement();
st.executeUpdate("UPDATE FlightLegInstance SET Pilot = '" + ID + "' WHERE FLNO = '" + FLNO + "' AND Seq = '" + Seq + "' AND FDate = '" + FDate + "'");
st.close();
break;
case 3:
System.out.print("Enter an ID: ");
ID = in.nextInt();
System.out.print("Enter a name: ");
name = in.next();
System.out.print("Enter date hired: ");
dateHired = in.next();
st = con.createStatement();
st.executeUpdate("INSERT INTO Pilot VALUES('" + ID + "', '" + name + "', '" + dateHired + "')");
st.close();
break;
case 4:
bool = false;
break;
}
}
con.close();
}
}