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.
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.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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
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;
}
}
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F16a501d0-ad86-4e86-a9d4-08a716d78319%2F98fce08b-765a-4923-a42b-1d3c02f030f0%2Fw9kgae_processed.jpeg&w=3840&q=75)
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
![swen2005 sales
SalesNumber: int(10)
SalesDate : date
# Sales Total : decimal(7,2)
V swen2005 salesdetails
number: int(10)
# SalesNumber : int(10)
Ⓒ prodid: varchar(20)
# price : decimal(7,2)
# qty: int(10)
swen2005 products
number : int(11)
prodid: varchar(20)
Ⓒ prodname : varchar(30)
# price : decimal(10,2)
#onhand int(11)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F16a501d0-ad86-4e86-a9d4-08a716d78319%2F98fce08b-765a-4923-a42b-1d3c02f030f0%2Fsgwjra_processed.png&w=3840&q=75)
Transcribed Image Text:swen2005 sales
SalesNumber: int(10)
SalesDate : date
# Sales Total : decimal(7,2)
V swen2005 salesdetails
number: int(10)
# SalesNumber : int(10)
Ⓒ prodid: varchar(20)
# price : decimal(7,2)
# qty: int(10)
swen2005 products
number : int(11)
prodid: varchar(20)
Ⓒ prodname : varchar(30)
# price : decimal(10,2)
#onhand int(11)
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY