Using the getSales() function as a reference, create a function thatt will take one parameter (string code) which is a product code (or part thereof), and when the search button is pressed, all sales that include this product code (or part thereof) will be displayed in the jTable. The date boxes in the GUI will be replaced with a text box. The schema of the database where the queries are being used is also attached. public List getSales(String fromDate, String toDate){ List salesList = new ArrayList<>(); try { String query = "SELECT sales_date, sales_number, prod_code, prod_name, unit_cost, quantity, sales_total " + "FROM Sales, SalesDetails, Product " + "WHERE Sales.sales_number = SalesDetails.sales_number " + "AND SalesDetails.prod_code = Product.prod_id " + "AND sales_date BETWEEN ? AND ?"; PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, fromDate); stmt.setString(2, toDate); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String salesDate = rs.getString("sales_date"); int salesNumber = rs.getInt("sales_number"); String prodCode = rs.getString("prod_code"); String prodName = rs.getString("prod_name"); double unitCost = rs.getDouble("unit_cost"); int quantity = rs.getInt("quantity"); double salesTotal = rs.getDouble("sales_total"); Pos pos = new Pos(salesDate, salesNumber, prodCode, prodName, unitCost, quantity, salesTotal); salesList.add(pos); } } catch (SQLException ex) { System.out.println(ex.getMessage()); } return salesList; }
Using the getSales() function as a reference, create a function thatt will take one parameter (string code) which is a product code (or part thereof), and when the search button is pressed, all sales that include this product code (or part thereof) will be displayed in the jTable. The date boxes in the GUI will be replaced with a text box. The schema of the database where the queries are being used is also attached. public List getSales(String fromDate, String toDate){ List salesList = new ArrayList<>(); try { String query = "SELECT sales_date, sales_number, prod_code, prod_name, unit_cost, quantity, sales_total " + "FROM Sales, SalesDetails, Product " + "WHERE Sales.sales_number = SalesDetails.sales_number " + "AND SalesDetails.prod_code = Product.prod_id " + "AND sales_date BETWEEN ? AND ?"; PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, fromDate); stmt.setString(2, toDate); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String salesDate = rs.getString("sales_date"); int salesNumber = rs.getInt("sales_number"); String prodCode = rs.getString("prod_code"); String prodName = rs.getString("prod_name"); double unitCost = rs.getDouble("unit_cost"); int quantity = rs.getInt("quantity"); double salesTotal = rs.getDouble("sales_total"); Pos pos = new Pos(salesDate, salesNumber, prodCode, prodName, unitCost, quantity, salesTotal); salesList.add(pos); } } catch (SQLException ex) { System.out.println(ex.getMessage()); } return salesList; }
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
Using the getSales() function as a reference, create a function thatt will take one parameter (string code) which is a product code (or part thereof), and when the search button is pressed, all sales that include this product code (or part thereof) will be displayed in the jTable. The date boxes in the GUI will be replaced with a text box. The schema of the database where the queries are being used is also attached.
public List<Pos> getSales(String fromDate, String toDate){
List<Pos> salesList = new ArrayList<>();
try {
String query = "SELECT sales_date, sales_number, prod_code, prod_name, unit_cost, quantity, sales_total "
+ "FROM Sales, SalesDetails, Product "
+ "WHERE Sales.sales_number = SalesDetails.sales_number "
+ "AND SalesDetails.prod_code = Product.prod_id "
+ "AND sales_date BETWEEN ? AND ?";
PreparedStatement stmt = conn.prepareStatement(query);
stmt.setString(1, fromDate);
stmt.setString(2, toDate);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
String salesDate = rs.getString("sales_date");
int salesNumber = rs.getInt("sales_number");
String prodCode = rs.getString("prod_code");
String prodName = rs.getString("prod_name");
double unitCost = rs.getDouble("unit_cost");
int quantity = rs.getInt("quantity");
double salesTotal = rs.getDouble("sales_total");
Pos pos = new Pos(salesDate, salesNumber, prodCode, prodName, unitCost, quantity, salesTotal);
salesList.add(pos);
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
return salesList;
}
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