public static int getPersonId(int id) { Connection con = getConnect(); ResultSet rs = null; int personId = 0; try { String SQL = "SELECT PersonId FROM 2761DB.Persons WHERE SchoolId = " + id; Statement stmt = con.createStatement(); rs = stmt.executeQuery(SQL); if (rs.next()) { rs.first(); personId = rs.getInt("PersonId"); } else { AddUserQuery addUserQuery = new AddUserQuery(); addUserQuery.setVisible(true); } } catch (Exception err) { MessageBox.infoBox(err.toString(), "Error in getPersonId"); } closeConnect(); return personId; }
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; }