问题描述:

Why can't I retrieve two values from different fields but same row?

If I write this, it works perfectly.

String sql = "SELECT * FROM soal ORDER BY RAND() LIMIT 1";

ResultSet rs = st.executeQuery(sql);

String question = rs.getString("questions");

But after I add this

String hint = rs.getString("hint_questions");

It won't work.

NOTE: I need two Strings, question, and hint from the same row and class for different purpose. So I have to use single select query SQL so that value from question and hint is related (from the same row).

网友答案:

You can try Either of the solution:

String var = rs.getString(1);
through index

Or

String var = rs.getString("column_name");
through column name
相关阅读:
Top