Section 5 Slides: Midterm Explanations + Preparation for hw5
February 3rd, 2022
Problem 3.b from Midterm
Write the SQL statements to create the tables representing the E/R diagram above. The keys eid, appId are integers, name, appName, platform, language are strings. Include all key and foreign key statements.
Problem 3.b from Midterm
create table Employee (eid int primary key, name text);
create table dba (eid int primary key references Employee, platform text);
create table SE (eid int primary key references Employee, language text);
create table Application (appId int primary key, appName text, manage int references dba );
create table develop (seId int references SE, appId int references Application);
Problem 4.b from Midterm
S(A,B,D)
Java Prepared Statements for hw5
SQL Injection and HW5
HW5 Notes
More HW5 Notes
SQL Injection
PreparedStatements
String rawQuery = “SELECT * FROM Flights WHERE origin_city = ? AND day_of_month = ?”;
PreparedStatement ps = conn.prepareStatement(rawQuery); // Pre-compiles the query into a PreparedStatement Object
ps.clearParameters(); // Clears parameters from previous use
ps.setString(1, originCity); // Sets the first parameter (the first “?”) to the value of the variable “originCity”
ps.setInt(2, dayOfMonth); // Sets the second parameter (the second “?”) to the value of the variable “dayOfMonth”
ResultSet rs = ps.executeQuery(); // Executes the query and stores the ResultSet in the variable “rs”
ResultSet
// ... continued from previous slide
ResultSet rs = ps.executeQuery();
while (rs.hasNext() && rs.next()) { // check if there is another row and move to the next row
String destCity = rs.getString(“dest_city”); // Gets the value of the attribute “dest_city” for the current row
...
} // When `next` finally returns false, we know we’ve seen every row
rs.close(); // Remember to close the ResultSet
Final HW5 Notes
Open Office Hours for Midterm and HW5