If the InvoiceID column is an INT type and the InvoiceDate column is a VARCHAR t
ID: 3704493 • Letter: I
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 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 can’t 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
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);
Explanation / Answer
Answer:----
1. d).
int id = dueInvoices.getInt(0);
String date = dueInvoices.getString(1);
2. b). statement.executeUpdate(query);
3. a). A SQLException is thrown at runtime because the SQL statement is coded incorrectly.
4. c). Rows from the Invoices table where InvoiceTotal is greater than 1
5. c). All rows in the Customers table where the FirstName column is “John”
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.