Question
If the InvoiceID column is an INT type and the InvoiceDate column is a VARCHAR type, which of the following statements returns those columns of
If the InvoiceID column is an INT type and the InvoiceDate column is a VARCHAR type, which of the following statements returns those columns of the current row?
Statement statement = connection.createStatement(); String query = "SELECT InvoiceID, InvoiceDate " + "FROM Invoices " + "ORDER BY InvoiceDate"; ResultSet dueInvoices = statement.executeQuery(query); dueInvoices.next();
a. | int id = dueInvoices.getInt(1); String date = dueInvoices.getVarChar(2); |
b. | int id = dueInvoices.getInt("InvoiceID"); String date = dueInvoices.getVarChar("InvoiceDate"); |
c. | int id = dueInvoices.getInt("InvoiceID"); String date = dueInvoices.getString("InvoiceDate"); |
d. | int id = dueInvoices.getInt(0); String date = dueInvoices.getString(1); |
Given the code below, which of the following statements deletes all rows from the Invoices table that have a value of 0 in the InvoiceTotal column?
String query = "DELETE FROM Invoices " + "WHERE InvoiceTotal = '0'"; Statement statement = connection.createStatement();
a. | statement.executeQuery(query); |
b. | statement.executeUpdate(query); |
c. | statement.deleteAllRows(); |
d. | statement.execute(); |
What happens when you try to compile and run the following code?
String query = "INSERT INTO Invoices (InvoiceDate InvoiceTotal) " + "VALUES ('2/10/01' '443.55')"; Statement statement = connection.createStatement(); statement.executeUpdate(query);
a. | A SQLException is thrown at runtime because the SQL statement is coded incorrectly. |
b. | A SQLException is thrown at runtime because the executeUpdate method cant accept a String object. |
c. | An error occurs at compile-time because the SQL statement is coded incorrectly. |
d. | This code compiles and runs without any problems. |
What does the invoices result set contain after the code that follows is executed?
String sql = "SELECT InvoiceDate, InvoiceTotal " + "FROM Invoices WHERE InvoiceTotal > ?"; PreparedStatement ps = connection.prepareStatement(sql); ps.setDouble(1, 100); ResultSet invoices = ps.executeQuery();
a. | Rows from the Invoices table where InvoiceTotal is greater than 100 |
b. | Rows from the Invoices table where InvoiceTotal is greater than 1 |
c. | Rows from the Invoices table where InvoiceTotal is greater than 0 |
d. | All rows from the Invoices table |
What rows are deleted after the code that follows is executed?
String sql = "DELETE FROM Customer " + "WHERE FirstName = ?"; PreparedStatement ps = connection.prepareStatement(sql); ps.setString(1, "John"); ps.executeUpdate();
a. | The first row in the Customers table. |
b. | The first row in the Customers table where the FirstName column is John |
c. | All rows in the Customers table where the FirstName column is John |
d. | All rows from the Customers table |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started