This method us missing four lines, which group of lines complete this method?

Consider the following database table:
<code>
Inventory Table
* Item_ID, Integer: PK
* Item_name, Varchar (20)
* Price, Numeric (10, 2)
* Quan, Integer
Consider the following method that updates the prices in the Inventory table:
public static void updatePrices{
// #1: missing line
Connection con) throws SQLException {
// #2: missing line
PreparedStatement updatePrices = con.prepareStatement (updatePricesString);
// #3: missing line
{
// #4: missing line
updatePrices.executeUpdate();
}
}
</code>

This method us missing four lines, which group of lines complete this method?

Consider the following database table:
<code>
Inventory Table
* Item_ID, Integer: PK
* Item_name, Varchar (20)
* Price, Numeric (10, 2)
* Quan, Integer
Consider the following method that updates the prices in the Inventory table:
public static void updatePrices{
// #1: missing line
Connection con) throws SQLException {
// #2: missing line
PreparedStatement updatePrices = con.prepareStatement (updatePricesString);
// #3: missing line
{
// #4: missing line
updatePrices.executeUpdate();
}
}
</code>

This method us missing four lines, which group of lines complete this method?

A.
1. HashMap<Integer, String> newPrices,
2. StringupdatePriceString =”UPDATE inventory SET price =? WHERE item_name’?'”;
3. For (map.Entry<Integer, String> x : newPrices.entrySet())
4. UpdatePrices.setFloat(1, x.getvalue().floatValue()); updatePrice.setString (2, x.getKey());

B.
1. HashMap<Integer, Float> newPrices,
2. StringupdatePriceString =”UPDATE inventory SET price =? WHERE item_id ‘?'”;
3. For (map.Entry<Integer, String> x : newPrices.entrySet())
4. UpdatePrices.setFloat(1, x.getvalue().floatValue()); updatePrice.setString (2,
x.getKey().intValue());

C.
1. HashMap<Integer, Float> newPrices,
2. StringupdatePriceString = �UPDATE inventory SET price =? Where item_id �?� �;
3. For (map.Entry<Integer, String> x : newPrices.entrySet())
4. UpdatePrices.setInt(1, x.getvalue().floatValue()); updatePrice.setString (2, x.getvalue());

D.
1. HashMap<Integer, Float> newPrices,
2. StringupdatePriceString = �UPDATE inventory SET price =? Where item_id �?� �;
3. For (map.Entry<Integer, String> x : newPrices.entrySet())
4. UpdatePrices.setInt(1, x.getvalue().floatValue()); updatePrice.setString (2,
x.getvalue().floatValue()

E.
1. HashMap<Integer, String> newPrices,
2. StringupdatePriceString = �UPDATE inventory SET price =? Where item_id �?� �;
3. For (map.Entry<Integer, String> x : newPrices.entrySet())
4. UpdatePrices,setString(1, x.getKey()); updatePrices.setFloat(2, x.getValue().floatValue());

F.
1. HashMap<Integer> newPrices,
2. StringupdatePriceString = �UPDATE inventory SET price =? Where item_id �?� �;
3. For (Integer x: newPrice)
4. updatePrice.setInt(1, x);

Explanation:
The first line should be HashMap<Integer, Float> newPrices, as in SQL numeric represent a float number, not an integeror string.
We also make sure to use floatValue() both in appropriate places in line 4.
Note: Map is an object that maps keys to values. A map cannot contain duplicate keys: Each key can map to at most one value. It models the mathematical function abstraction.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Marian

Marian

not D. I guess the correct option is missing

zzZZzzzzZZzzz

zzZZzzzzZZzzz

+1
B if
3 for(Map.Entry x : newPrices.entrySet())
4 updatePrice.setFloat(1, x.getValue().floatValue()); updatePrice.setInt(2, x.getKey().intValue());