Exemple #1
0
  private void btnAddActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnAddActionPerformed
    ClassModal c = (ClassModal) cbbClass.getSelectedItem();
    String sql =
        "insert into Student([Name], [Score], [classId])"
            + "values('"
            + txtName.getText().trim()
            + "', "
            + txtScore.getText().trim()
            + ", "
            + c.id
            + ")";
    System.out.println(sql);

    try (Connection cn = Tools.getConn();
        Statement st = cn.createStatement(); ) {
      int rows = st.executeUpdate(sql);
      if (rows > 0) {
        JOptionPane.showMessageDialog(this, "Add successful");
        parent.initStudent(null);
        this.dispose();
      }
    } catch (SQLException ex) {
      Logger.getLogger(StudentManagementSystem.class.getName()).log(Level.SEVERE, null, ex);
    }
  } // GEN-LAST:event_btnAddActionPerformed
  public static void main(String[] args) {

    ClassPathXmlApplicationContext context =
        new ClassPathXmlApplicationContext("spring-context.xml");
    context.start();

    Student std = (Student) context.getBean("student1");

    StudentManagementSystem sms = (StudentManagementSystem) context.getBean("sms");

    sms.listAllStudents();

    System.out.println("\n#######################################\n");

    std = (Student) context.getBean("student4");
    sms.registerStudent(std);
    std = (Student) context.getBean("student5");
    sms.registerStudent(std);
    std = (Student) context.getBean("student6");
    sms.registerStudent(std);

    sms.listAllStudents();
  }