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;
}
}
Expert Solution
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
Recommended textbooks for you
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…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
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…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
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)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY