Question: Use project9 solution for following changes: 1. change the combo box for courses into Listview with multiple select. 2. Register button will be able to
Use project9 solution for following changes: 1. change the combo box for courses into Listview with multiple select.
2. Register button will be able to register more than one courses using Listview
3. You must use Batch statements to register all courses user selected in one execute.
import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene;
import java.sql.*;
public class Project9 extends Application { // Declare an array of Strings for Course Names private String connectionUrl = "jdbc:sqlserver://s16988308.onlinehome-server.com";
// Declare the JDBC objects. private Connection connection = null; private PreparedStatement statement = null; private ResultSet resultSet = null; private CallableStatement callableStatement = null; @Override // Override the start method in the Application class public void start(Stage primaryStage) {
primaryStage.setTitle("Course Registration"); // Set the stage title // Create GridPane GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25,25,25,25));
// Title Text scenetitle = new Text("Course Registration"); grid.add(scenetitle, 0, 0, 2, 1);
// SSN TextField Label userName = new Label("User SSN:"); grid.add(userName, 0, 1);
final TextField ssnTextField = new TextField(); grid.add(ssnTextField, 1, 1); //ssnTextField.setPrefWidth(200); ssnTextField.setMaxWidth(200); //ssnTextField.setMinWidth(100); // Course ComboBox Label pw = new Label("Course: "); grid.add(pw, 0, 2); final ComboBox
// TextArea to display my registration HBox txtHbox = new HBox(10); txtHbox.setAlignment(Pos.BOTTOM_CENTER); final TextArea txtArea = new TextArea(); txtArea.setMinWidth(200); txtArea.setMinHeight(150); txtHbox.getChildren().add(txtArea); grid.add(txtHbox, 0, 5, 2, 1); Scene scene = new Scene(grid, 600, 500); primaryStage.setScene(scene); primaryStage.show();
primaryStage.setTitle("Status: Getting Courses from Database"); // Set the stage title
// Establish the connection and get courses try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); connection = DriverManager.getConnection(connectionUrl, "cst3613", "password1"); Statement statement = connection.createStatement(); // Execute a statement ResultSet resultSet = statement.executeQuery("select courseID from Course order by courseID;"); // Iterate through the result and print the student names ObservableList
// Input SSN to variable String ssn = ssnTextField.getText();
// Input Course ID from Combobox String courseId = courseCombo.getValue().toString();
// Prepare call to stored procedure callableStatement = connection.prepareCall("{call insertStudent(?,?)}");
callableStatement.setString(1,ssn); callableStatement.setString(2,courseId);
callableStatement.execute(); txtArea.appendText("Course added. "); }
// Handle any errors that may have occurred. catch (Exception f) { // Error Handling here?? txtArea.appendText("Failed to add course "); f.printStackTrace(); }
finally { if (resultSet != null) try { resultSet.close(); } catch(Exception f) {} if (statement != null) try { statement.close(); } catch(Exception f) {} // if (connection != null) try { connection.close(); } catch(Exception f) {} }
} }); // Button Action settings showbtn.setOnAction(new EventHandler
// Input SSN to variable String ssn = ssnTextField.getText();
// Create and execute an SQL statement that returns some data. String SQL = "SELECT cs.courseID, cs.title, en.grade FROM students st, enrollment en, course cs " + "WHERE st.ssn = en.ssn AND en.courseId = cs.courseID " + "AND st.ssn = ?;";
statement = connection.prepareStatement(SQL); statement.setString(1,ssn); resultSet = statement.executeQuery(); if (resultSet.next() == false) txtArea.appendText("No result found. "); // Iterate through the data in the result set and display it. while (resultSet.next()) { txtArea.appendText(resultSet.getString("courseID") + "\t" + resultSet.getString("title") + "\t" + resultSet.getString("grade") + " "); } }
// Handle any errors that may have occurred. catch (Exception f) { // Error Handling here?? f.printStackTrace(); }
finally { if (resultSet != null) try { resultSet.close(); } catch(Exception f) {} if (statement != null) try { statement.close(); } catch(Exception f) {} // if (connection != null) try { connection.close(); } catch(Exception f) {} }
} }); } class EXITHandlerClass implements EventHandler
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
