public static void closeConnect() { try { con.close(); } catch (SQLException e) { MessageBox.infoBox(e.toString(), "Error in closeConnect"); } }
private void submitButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_submitButtonActionPerformed // TODO add your handling code here: Connection con = FrameLogin.getConnect(); String SQLInsert = "INSERT INTO `2761DB`.`Persons` (`FirstName`, `LastName`, `CellPhoneNo`, `HomePhoneNo`, " + "`SchoolId`, `Graduation Year`, `Gender`) VALUES ('" + firstName.getText() + "', '" + lastName.getText() + "', '" + cellPhone.getText() + "', '" + homePhone.getText() + "', '" + studentId.getText() + "', '" + gradYear.getText() + "', '" + (String) (gender.getSelectedItem()) + "');"; String SQLUpdate = "UPDATE `2761DB`.`Persons` SET `FirstName` = '" + firstName.getText() + "', `LastName` = '" + lastName.getText() + "', `CellPhoneNo` = ' " + cellPhone.getText() + "', `HomePhoneNo` = '" + homePhone.getText() + "', `Graduation Year` = '" + gradYear.getText() + "', `Gender` = '" + (String) (gender.getSelectedItem()) + "' WHERE `PersonId` = '" + Id + "';"; // UPDATE `2761DB`.`Persons` SET `FirstName`='Robbie', `LastName`='Tacescu', `CellPhoneNo`='', // `HomePhoneNo`='559300', `SchoolId`='15648916', `Graduation Year`='6545', `Gender`='males' // WHERE // `PersonId`='42'; try { if (isEdit) { Statement stmt = con.createStatement(); // System.out.println(SQLUpdate); stmt.executeUpdate(SQLUpdate); } else { Statement stmt = con.createStatement(); // System.out.println(SQLInsert); stmt.executeUpdate(SQLInsert); } } catch (SQLException err) { MessageBox.infoBox(err.toString(), "Error in AddUserForm submitButton"); } FrameLogin.closeConnect(); this.dispose(); } // GEN-LAST:event_submitButtonActionPerformed
private void logIn(int personId) { Connection con = getConnect(); try { // MessageBox.infoBox("You have successfully logged in", "Login"); // INSERT INTO LogInOut (PersonId, TimeIn) VALUES (1, NOW()) String SQLLogin = "******" + personId + ", NOW())"; Statement stmtLogin = con.createStatement(); stmtLogin.executeUpdate(SQLLogin); Update_table(); } catch (SQLException err) { MessageBox.infoBox(err.toString(), "Error"); } closeConnect(); }
private void logOut(int personId) { Connection con = getConnect(); try { // MessageBox.infoBox("You have successfully logged out", "Logout"); // UPDATE LogInOut SET TimeOut = NOW() WHERE PersonId = 1 AND TimeOut IS NULL String SQLLogin = "******" + personId + " AND TimeOut IS NULL"; Statement stmtLogin = con.createStatement(); stmtLogin.executeUpdate(SQLLogin); Update_table(); } catch (SQLException err) { System.out.println(err); MessageBox.infoBox(err.toString(), "Error"); } closeConnect(); }
public static boolean isIdFound(int id) { Connection con = getConnect(); boolean isFound = false; try { String SQL = "SELECT PersonId, FirstName, LastName, SchoolId FROM 2761DB.Persons WHERE SchoolId = " + id; Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery(SQL); if (rs.first()) { isFound = true; } else { AddUserQuery addUser = new AddUserQuery(); addUser.setVisible(true); } } catch (SQLException err) { System.out.println(err); MessageBox.infoBox(err.toString(), "Error"); } closeConnect(); return isFound; }