0

I have created a dialog box which shows the instructors and courses where I want the admin to assign an instructor to the course. This is the dialog box: enter image description here

When I press on assign, it will fill the instructor column in the JTable below with the instructor's name (from the Name textfield).

However, I also want a dialog box to appear which displays all the courses where the name of the instructor is the one in the textfield. In this case, I want a dialog box that shows that information of the courses with the instructor name from the textfield name. (information same as the courses table)

This is actionlistener for assign button:

Assign.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        Connection con = coursescon();
        String InstructorName = NameField.getText();
        String CourseCode = CourseCodeField.getText();
        
        String query = "UPDATE courseslist SET instructor = '"+InstructorName+"' WHERE code = " +CourseCode+";";
        try {
            PreparedStatement pSt = con.prepareStatement(query);
            pSt.executeUpdate();
            
            DefaultTableModel model = (DefaultTableModel) CoursesTable.getModel();
            model.setRowCount(0);
            showCourses();
        
            //JOptionPane.showMessageDialog(null, "Assigned Successfully!");
            //AssignedCoursesDialog Dialog = new AssignedCoursesDialog();
            //DefaultTableModel DialogModel = (DefaultTableModel) Dialog.Assignedtable.getModel();
        }

How can I do the dialog box or the GUI if a dialog box is difficult to do?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
anon
  • 3
  • 3
  • 1
    1) you are using the PreparedStatement incorrectly. The purpose of the PreparedStatement is to simplify the SQL string by passing parameters to the statement. This question: https://stackoverflow.com/questions/70149747/i-keep-getting-errors-when-trying-to-put-the-data-of-my-java-netbeans-j-table-re shows the basics of using the PreparedStatement. 2) This answer: shows the basics of creating a window with a JTable created from data in the ResultSet from an SQL query. – camickr Nov 29 '21 at 14:41
  • @camickr Could it be that you forgot to add a link for 2), or did I misinterpret your comment? – TT. Nov 29 '21 at 14:49
  • @TT. oops... the OP can check out: https://stackoverflow.com/questions/55627828/how-to-get-a-defaulttablemodel-objects-data-into-a-subclass-of-defaulttablemode/55635012#55635012 for a basic example. – camickr Nov 29 '21 at 16:50

0 Answers0