Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

The following java function executes an SQL query based on the inputs from the combo boxes and text box from the screen shown and is supposed to return a list of items that match the query. The input string is a string of the field, operator and criteria text from the boxes separated by commas. However, the method is not currently functional and must be modified to enact the query. Modifiy the function so that it works properly. An image of the database schema has also been attached as well as the product class.

public List<Product> getProductByCriteria(String criteria) {
if (openConnection()) {
try {
List<Product> items = new ArrayList<>();
Product temp = null;
String[] fields = criteria.split(",");
String query = "SELECT * FROM products WHERE " + fields[0] + fields[1] + fields[2];
stmt = conn.prepareStatement(query);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
temp = new Product(rs.getInt("number"), rs.getString(2), rs.getString("prodname"),
rs.getFloat("price"), rs.getInt("onhand"));
items.add(temp);
}
stmt.close();
closeConnection();
return items;
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
closeConnection();
return null;
}
class Product{
public int number;
public String prodID;
public String prodName;
public float prodPrice;
public int prodOnHand;
Product(int num,String id, String name, float price, int qty)
{
number=num;
prodID=id;
prodName=name;
prodPrice=price;
prodOnHand=qty;
}
}
Transcribed Image Text:Product Finder Screen Product ID ProdID 4225 4116 5486 6362 1096 9813 Equal Product Name Cheese Feta Beef Ox Tongue Plasticknivesblack Arrowroot Glass Clear 8 Oz Wine Muscadet Sur Lie Price 21.77 49.71 11.08 60.64 41.4 34.1 Search On Hand I 190 239 139 118 71 5 X
Transcribed Image Text:swen2005 sales SalesNumber: int(10) SalesDate : date # Sales Total : decimal(7,2) V swen2005 salesdetails number: int(10) # SalesNumber : int(10) C prodid: varchar(20) # price : decimal(7,2) # qty: int(10) swen2005 products number : int(11) prodid: varchar(20) C prodname : varchar(30) # price : decimal(10,2) #onhand int(11)
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY