final void initHuman() {
   String sql = "Select * from tblHuman where id = ?";
   try (Connection cn = Tools.getConn();
       PreparedStatement pst = cn.prepareStatement(sql); ) {
     pst.setInt(1, Integer.parseInt(vRow.get(0).toString()));
     ResultSet rs = pst.executeQuery();
     if (rs.next()) {
       txtUserName.setText(rs.getString(2));
       txtBirthDay.setDate(rs.getDate(3));
       txtGender.setText(rs.getString(4));
       txtBirthPlace.setText(rs.getString(5));
       txtNativeCountry.setText(rs.getString(6));
       txtNation.setText(rs.getString(7));
       txtReligion.setText(rs.getString(8));
       txtOccupation.setText(rs.getString(9));
       txtWorkPlace.setText(rs.getString(10));
       txtIDCard.setText(rs.getString(11));
       txtArrivalDate.setDate(rs.getDate(12));
       byte[] b = rs.getBytes(13);
       ImageIcon icon = new ImageIcon(b);
       Image img = icon.getImage();
       img = img.getScaledInstance(lblImage.getWidth(), lblImage.getHeight(), Image.SCALE_SMOOTH);
       lblImage.setIcon(new ImageIcon(img));
       txtRoomID.setText(rs.getString(14));
       txtEmail.setText(rs.getString(15));
     }
   } catch (SQLException ex) {
     Logger.getLogger(EditHumanDialog.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
Example #2
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
Example #3
0
 void initClass() {
   cbbClass.removeAllItems();
   try (Connection cn = Tools.getConn();
       Statement st = cn.createStatement();
       ResultSet rs = st.executeQuery("Select * from tblClass"); ) {
     while (rs.next()) {
       ClassModal c = new ClassModal(rs.getInt(1), rs.getString(2));
       cbbClass.addItem(c);
     }
   } catch (SQLException ex) {
     Logger.getLogger(StudentManagementSystem.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
  private void btnSaveActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnSaveActionPerformed
    String sql =
        "Update tblHuman set Name = ?,Birthday = ?,Gender = ?,Birthplace = ?,[Native Country] = ?,Nation = ?,Religion = ?,Occupation = ?,WorkPlace = ?,[ID Card] = ?,[Date of arrival] = ?,Image = ?,RoomID = ?,Email = ? where id = ?";
    Connection cn = Tools.getConn();
    try {
      cn.setAutoCommit(false);
      PreparedStatement pst = cn.prepareStatement(sql);

      pst.setString(1, txtUserName.getText().trim());
      pst.setDate(2, new Date(txtBirthDay.getDate().getTime()));
      pst.setNull(3, java.sql.Types.BIT);
      pst.setString(4, txtBirthPlace.getText().trim());
      pst.setString(5, txtNativeCountry.getText().trim());
      pst.setString(6, txtNation.getText().trim());
      pst.setString(7, txtReligion.getText().trim());
      pst.setString(8, txtOccupation.getText().trim());
      pst.setString(9, txtWorkPlace.getText().trim());
      pst.setString(10, txtIDCard.getText().trim());
      pst.setDate(11, new Date(txtArrivalDate.getDate().getTime()));

      //////////////////////////
      if (f.exists() || !f.isDirectory()) {
        InputStream image = new FileInputStream(f);
        pst.setBinaryStream(12, image);
      } else {
        pst.setNull(12, java.sql.Types.VARBINARY);
      }

      pst.setInt(13, Integer.parseInt(txtRoomID.getText().trim()));
      pst.setNull(14, java.sql.Types.VARBINARY);
      pst.setInt(15, Integer.parseInt(vRow.get(0).toString()));
      pst.executeUpdate();
      cn.commit();
      cn.setAutoCommit(true);
      JOptionPane.showMessageDialog(this, "Replace successful");
      peopleDetail.initPeopleDetail(null);
      peopleDetail.initWidthTable();
      this.dispose();

    } catch (SQLException ex) {
      Logger.getLogger(EditHumanDialog.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
      Logger.getLogger(EditHumanDialog.class.getName()).log(Level.SEVERE, null, ex);
    }
  } // GEN-LAST:event_btnSaveActionPerformed