Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help adding the following code into the first 2 event action handlers, as well as new code for the last 2.. // Print

image text in transcribed

I need help adding the following code into the first 2 event action handlers, as well as new code for the last 2..

// Print Order Total for Order Number String query = "SELECT ProductID, Quantity, UnitPrice, Discount FROM OrderDetails WHERE OrderID = " + textField1.getText() + " ORDER BY Quantity ASC"; statement = connection.createStatement(); resultSet = statement.executeQuery(query); showContents(resultSet);

// Print Order Details for Order Number String query = "SELECT OrderDate, Freight, ProductID, Quantity, UnitPrice, Discount FROM Orders inner join OrderDetails on OrderID = " + textField2.getText(); statement = connection.createStatement(); resultSet = statement.executeQuery(query); showContents(resultSet);

What's supposed to happen is that the user enters a number(or state for the other option) it displays info from a query based on the info given.

Here is the code.

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.example.exercise32_06; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; import java.sql.*; import javafx.beans.property.SimpleStringProperty; import javafx.beans.value.ObservableValue; import javafx.scene.control.TableColumn.CellDataFeatures; import javafx.util.Callback; public class Exercise32_06 extends Application { public static void main(String[] args) { launch(args); } // Statement for executing queries private Statement stmt; private TextField tfTableNum = new TextField(); private TextField tfTableNum2 = new TextField(); private TextField tfTableName = new TextField(); private TextField tfTableNum3 = new TextField(); private ObservableList data; private TableView tableview; @Override // Override the start method in the Application class public void start(Stage primaryStage) { VBox vBox = new VBox(10); // Initialize database connection and create a Statement object tableview = new TableView(); initializeDB(); Button btTotal = new Button("Order Details"); Button btOrder = new Button("Orders"); Button btCust = new Button("Customers"); Button btEmploy = new Button("Employees"); HBox hBox = new HBox(5); hBox.getChildren().addAll(new Label("Print order total (not including the freight cost) for a given order number"), tfTableNum, (btTotal)); HBox hBox2 = new HBox(5); hBox2.getChildren().addAll(new Label("Print all order details for a given number"), tfTableNum2, (btOrder)); HBox hBox3 = new HBox(5); hBox3.getChildren().addAll(new Label("Print the names and cities of all customer in a given state"), tfTableName, (btCust)); HBox hBox4 = new HBox(5); hBox4.getChildren().addAll(new Label("Print the names of all employees who have a birthday in a given year"), tfTableNum3, (btEmploy)); vBox.getChildren().addAll(hBox, hBox2,hBox3, hBox4, tableview); tfTableNum.setPrefColumnCount(6); // btTotal.setOnAction(e -> showContents()); tfTableNum2.setPrefColumnCount(6); //btTotal.setOnAction(e -> showContents()); tfTableName.setPrefColumnCount(6); // btTotal.setOnAction(e -> showContents());tfTableNum.setPrefColumnCount(6); tfTableNum3.setPrefColumnCount(6); // btTotal.setOnAction(e -> showContents()); // Create a scene and place it in the stage Scene scene = new Scene(vBox, 500, 180); primaryStage.setTitle("Prgramming Exercise 03"); primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } private void initializeDB() { try { // Load the JDBC driver Class.forName("net.ucanaccess.jdbc.UcanaccessDriver"); System.out.println("Driver loaded"); // Establish a connection Connection connection = DriverManager.getConnection("jdbc:ucanaccess://C:/Data/Northwind.mdb"); // Create a statement stmt = connection.createStatement(); } catch (Exception ex) { ex.printStackTrace(); } } private void showContents(ResultSet resultset) { ObservableList data = FXCollections.observableArrayList(); try { for (int i = 0; i , ObservableValue>() { public ObservableValue call(CellDataFeatures param) { if (param == null || param.getValue() == null || param.getValue().get(j) == null) { return null; } return new SimpleStringProperty(param.getValue().get(j).toString()); } }); tableview.getColumns().addAll(col); System.out.println("Column [" + i + "] "); } while (resultset.next()) { // Iterate Row ObservableList row = FXCollections.observableArrayList(); for (int i = 1; i  

// Style I Idea (GUI Design) II Northwind Database Querv Tool // Tips for the code (Loading the DB driver and connecting your application to the DB. Refer the Lesson 4HW code or Tips for doing Lesson 4HW ) InitializeDB() code is almost identical to the code that you have used in Lesson 4 Homework. However, the database is different. So, the following code is needed, and you have to locate the Northwind.mdb in C;/Data directory. Download Northwind.mdb from "Access Databases for JDBC" folder in Lesson 4 of the Blackboard (download and unzip)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions