content: 
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.swing.JOptionPane;
  import javax.swing.table.DefaultTableModel;
  
  public class GetAllTeacherCourse extends javax.swing.JFrame {
  
      /**
       * Creates new form GetAllTeacherCourse
       */
      public GetAllTeacherCourse() {
          initComponents();
      }
  
      /**
       * This method is called from within the constructor to initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is always
       * regenerated by the Form Editor.
       */
      @SuppressWarnings("unchecked")
      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
      private void initComponents() {
  
          jPanel1 = new javax.swing.JPanel();
          id = new javax.swing.JTextField();
          jButton1 = new javax.swing.JButton();
          jLabel1 = new javax.swing.JLabel();
          jLabel2 = new javax.swing.JLabel();
          jScrollPane1 = new javax.swing.JScrollPane();
          Table = new javax.swing.JTable();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
          jPanel1.setBackground(new java.awt.Color(0, 64, 128));
  
          id.setText("Enter Instructor ID");
          id.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  idActionPerformed(evt);
              }
          });
  
          jButton1.setBackground(new java.awt.Color(0, 64, 128));
          jButton1.setForeground(new java.awt.Color(255, 255, 255));
          jButton1.setText("Enter");
          jButton1.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  jButton1ActionPerformed(evt);
              }
          });
  
          jLabel2.setIcon(new javax.swing.ImageIcon("C:\\Users\\ahmed\\OneDrive\\Desktop\\download-removebg-preview (1) - Copy.png")); // NOI18N
  
          Table.setModel(new javax.swing.table.DefaultTableModel(
              new Object [][] {
                  {null, null},
                  {null, null},
                  {null, null},
                  {null, null}
              },
              new String [] {
                  "Inst_ID", "Sec_ID"
              }
          ));
          jScrollPane1.setViewportView(Table);
  
          javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
          jPanel1.setLayout(jPanel1Layout);
          jPanel1Layout.setHorizontalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel1Layout.createSequentialGroup()
                  .addGap(35, 35, 35)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addGap(77, 77, 77))
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                          .addComponent(jButton1)
                          .addGap(90, 90, 90)))
                  .addComponent(jLabel2)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(jLabel1)
                  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
          );
          jPanel1Layout.setVerticalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel1Layout.createSequentialGroup()
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addContainerGap()
                          .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addGap(71, 71, 71)
                          .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                              .addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addComponent(jButton1))
                          .addGap(40, 40, 40)
                          .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 381, javax.swing.GroupLayout.PREFERRED_SIZE))
                      .addComponent(jLabel2))
                  .addContainerGap(43, Short.MAX_VALUE))
          );
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          );
  
          pack();
      }// </editor-fold>//GEN-END:initComponents
  
      private void idActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idActionPerformed
          // TODO add your handling code here:
      }//GEN-LAST:event_idActionPerformed
  
      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
          String query = "SELECT Inst_ID, Sec_ID FROM Teaches WHERE Inst_ID = ?;";
  
          try (Connection connection = ConnectToDB.getConnection(); java.sql.PreparedStatement preparedStatement = connection.prepareStatement(query)) {
  
              // Set the parameter for the query
              preparedStatement.setInt(1, Integer.parseInt(id.getText())); // `id` is the input field for Instructor ID
  
              // Execute the query
              ResultSet resultSet = preparedStatement.executeQuery();
  
              // Get the table model and clear existing rows (optional, to prevent duplicate data)
              DefaultTableModel tableModel = (DefaultTableModel) Table.getModel();
              tableModel.setRowCount(0); // Clear the table before adding new data
  
              // Populate the table model with data
              while (resultSet.next()) {
                  Object[] row = {
                      resultSet.getInt("Inst_ID"), // Replace with "Inst_ID" column
                      resultSet.getInt("Sec_ID") // Replace with "Sec_ID" column
                  };
                  tableModel.addRow(row); // Add row to the table model
              }
  
          } catch (SQLException e) {
              e.printStackTrace();
              JOptionPane.showMessageDialog(this, "Error fetching data: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
          } catch (NumberFormatException e) {
              JOptionPane.showMessageDialog(this, "Invalid Instructor ID. Please enter a valid number.", "Error", JOptionPane.ERROR_MESSAGE);
          }
  
      }//GEN-LAST:event_jButton1ActionPerformed
  
      /**
       * @param args the command line arguments
       */
      public static void main(String args[]) {
          /* Set the Nimbus look and feel */
          //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
          /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
           * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
           */
          try {
              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                  if ("Nimbus".equals(info.getName())) {
                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
                      break;
                  }
              }
          } catch (ClassNotFoundException ex) {
              java.util.logging.Logger.getLogger(GetAllTeacherCourse.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (InstantiationException ex) {
              java.util.logging.Logger.getLogger(GetAllTeacherCourse.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex) {
              java.util.logging.Logger.getLogger(GetAllTeacherCourse.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
              java.util.logging.Logger.getLogger(GetAllTeacherCourse.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          }
          //</editor-fold>
  
          /* Create and display the form */
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  new GetAllTeacherCourse().setVisible(true);
              }
          });
      }
  
      // Variables declaration - do not modify//GEN-BEGIN:variables
      private javax.swing.JTable Table;
      private javax.swing.JTextField id;
      private javax.swing.JButton jButton1;
      private javax.swing.JLabel jLabel1;
      private javax.swing.JLabel jLabel2;
      private javax.swing.JPanel jPanel1;
      private javax.swing.JScrollPane jScrollPane1;
      // End of variables declaration//GEN-END:variables
  }
  