Q:

Retrieve Data from a SQL Query (SELECT FROM WHERE) in java

Well I was wondering if there is any other way to get data from a SQL Query.
What I mean is that the "main" code that I always find is
Connection con = (connect to db)
PreparedStatement st = con.prepareStatement(....);
ResultSet rs = ps.executeQuery();

while (rs.next())
{
  //do something
}

But if I want to retrieve specific data for example lets assume that my query is
            Connection con = L2DatabaseFactory.getInstance().getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT login,email FROM accounts WHERE login=?");
            ps.setString(1, account);
            ResultSet rs = ps.executeQuery();

            while (rs.next())
            {
                if (rs.getString("login").equals(account))
                {
                    email = rs.getString("email");
                    break;
                }
            }

Is there any other way except that while loop to retrieve data?

A:

The if condition inside the while loop is completely redundant - the where clause takes care of it and assures that any data returned from this query would have a login field that's equal to the value of account. 
If you're sure there's no more than one row like this (e.g., the login column is a unique identifier in your table), you could just replace the while loop with an if:
// Check that such a logic exists
if (rs.next()) {
    email = rs.getString("email");
}

// for good measures, just double check there isn't more than one 
// of these logins:
if (rs.next()) {
    throw new Exception ("This cannot be!"); // Or something more sensible
}

