Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. Write code that executes the following SELECT statement: SELECT Title, Year F

ID: 3780006 • Letter: 5

Question

5.   Write code that executes the following SELECT statement:

SELECT Title, Year

FROM Movies

WHERE DIRECTOR = 37

ORDER BY Year DESC

You may assume that a connection to the database has already been established and is stored in a Connection object named dbcon. Store the result set in a variable named result. (You must declare the result variable, but don’t worry about catching exceptions.)

     6.   Assume that a ResultSet object named result contains the results of the following query:

SELECT Title, Year

FROM Movies

WHERE Director = 37

ORDER BY Year DESC

Assuming that the Title and Year columns store string data, write code that prints the title and year for each row in the result set to the console. The output should look like this:

The Birds (1963)

Psycho (1960)

North By Northwest (1959)

Explanation / Answer

JAVA CODE :

// Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql="SELECT Title, Year FROM Movies WHERE DIRECTOR = 37 ORDER BY Year DESC";
ResultSet result = stmt.executeQuery(sql);

// Extract data from result set
while(result.next()){
//Display values
System.out.print( result.getString("Title")+"(" + result.getString("Year")+")");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote