@Override public Account getAccountByEmail(Account account) throws DAOException { Connection connect = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; // boolean isAuthenticated = false; // Integer accountId = 0; try { connect = ConnectionPool.getPool().getConnection(); preparedStatement = connect.prepareStatement(SELECT_ACCOUNT_DETAILS_BY_LOGIN_AND_PASSWORD); preparedStatement.setString(1, account.getEmail()); preparedStatement.setString(2, account.getPassword()); resultSet = preparedStatement.executeQuery(); resultSet.next(); account.setId(resultSet.getInt(AccountColumns.Id.getName())); account.setFirstName(resultSet.getString(AccountColumns.FirstName.getName())); account.setLastName(resultSet.getString(AccountColumns.LastName.getName())); account.setMiddleName(resultSet.getString(AccountColumns.MiddleName.getName())); account.setRoleId(resultSet.getInt(AccountColumns.RoleId.getName())); } catch (Exception e) { throw new DAOException(e); } finally { ConnectionPool.releaseConnection(connect, preparedStatement, resultSet); } return account; }
@Override public void saveAccount(Account account) throws DAOException { Connection connect = null; PreparedStatement preparedStatement = null; try { connect = ConnectionPool.getPool().getConnection(); preparedStatement = connect.prepareStatement(SAVE_ACCOUNT_SQL); preparedStatement.setString(1, account.getEmail()); preparedStatement.setString(2, account.getPassword()); preparedStatement.setString(3, account.getFirstName()); preparedStatement.setString(4, account.getLastName()); preparedStatement.setString(5, account.getMiddleName()); preparedStatement.executeUpdate(); } catch (Exception e) { throw new DAOException(e); } finally { ConnectionPool.releaseConnection(connect, preparedStatement); } }
@Override public boolean checkAccountAuthentication(Account account) throws DAOException { Connection connect = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; boolean isAuthenticated = false; try { connect = ConnectionPool.getPool().getConnection(); preparedStatement = connect.prepareStatement(SELECT_ACCOUNT_DETAILS_BY_LOGIN_AND_PASSWORD); preparedStatement.setString(1, account.getEmail()); preparedStatement.setString(2, account.getPassword()); resultSet = preparedStatement.executeQuery(); isAuthenticated = resultSet.next(); } catch (Exception e) { throw new DAOException(e); } finally { ConnectionPool.releaseConnection(connect, preparedStatement, resultSet); } return isAuthenticated; }