Frage

How would I be able to print result set into text fields? So far I can only print one out but not the second. Assume I have only 2 items in the result set and I want to put them into two separate textfields, so far I have:

String Question = (jQuestion.getText());
        String sql = "SELECT a.options FROM answers a, questions q WHERE q.question = '"+Question+"' AND a.question_id = q.question_id";
        pst = conn.prepareStatement(sql);
        rs = pst.executeQuery();
        while (rs.next()) {
            String option = rs.getString("options");
            jAnswerA.setText(option);
        }while (rs.next()) {
            String optionB = rs.getString("options");
            jAnswerB.setText(optionB);
        }
War es hilfreich?

Lösung

if (rs.next()) {
     String option = rs.getString("options");
     jAnswerA.setText(option);
};

if (rs.next()) {
     String optionB = rs.getString("options");
     jAnswerB.setText(optionB);
};
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top