结果集将显示在多个文本字段中

时间:2014-03-29 01:27:12

标签: sql database textfield resultset

如何将结果集打印到文本字段中?到目前为止,我只能打印一个而不是第二个。假设我在结果集中只有2个项目,并且我想将它们放入两个单独的文本字段中,到目前为止我有:

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);
        }

1 个答案:

答案 0 :(得分:0)

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

if (rs.next()) {
     String optionB = rs.getString("options");
     jAnswerB.setText(optionB);
};