55.2k views
3 votes
What statement needs to be included below to retrieve all rows from the Invoices table with InvoiceTotal greater than 100?

String sql = "SELECT InvoiceDate, InvoiceTotal "
+ "FROM Invoices WHERE InvoiceTotal > ?";
PreparedStatement ps = connection.prepareStatement(sql);
//what goes here
ResultSet invoices = ps.executeQuery();

a. ps.setValue(0, 100);
b. ps.setValue(1, 100);
c. ps.setDouble(0, 100);
d. ps.setDouble(1, 100);

User JBond
by
5.1k points

1 Answer

2 votes

ps.setValue(1, 100); statement needs to be included below to retrieve all rows from the Invoices table with InvoiceTotal greater than 100

b. ps.setValue(1, 100);

Step-by-step explanation:

Here, in this code snippet, we have to return rows of InvoiceDate and InvoiceTotal from the table Invoices only when the InvoiceTotal is greater than 100. PreparedStatement is a subtype of Statement class Java. It is used to parameterize a query.

Since we have to display the records from the Invoice table after checking the condition, we call the method of PreparedStatement class, ps.setDouble(1,100) as the records start from 1 and end at 100.

User Gsquare
by
5.5k points