Do I need a loop if I am only returning one row using SQLite? (Android Dev)
<p>I have been using the following metod using a for loop but it occurred to me that I am only returning one row- so is it necessary to have a loop? </p>

<p>i.e my code resembles this: </p>

<pre><code>public String topSwimmerSponsor() {
    Cursor c = ourDatabase.rawQuery("SELECT " + KEY_SWIMMERLAPS + " * "
            + KEY_SPONSOR + " AS result, " + KEY_NAME + " FROM "
            + DATABASE_TABLE + " ORDER BY result DESC limit 1", null);

    String result = "";

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        result = result + c.getString(1) + "\n";
    }
    return result;
}
</code></pre>

<p>However I am attempting to change it to the following: </p>

<pre><code>public String topSwimmerSponsor() {
    Cursor c = ourDatabase.rawQuery("SELECT " + KEY_SWIMMERLAPS + " * "
            + KEY_SPONSOR + " AS result, " + KEY_NAME + " FROM "
            + DATABASE_TABLE + " ORDER BY result DESC limit 1", null);

    String result = "";

    result = result + c.getString(1) + "\n";

    return result;
}
</code></pre>

<p>However my app crashes. What is the correct way to implement this? Thanks. </p>
