in java.How to save a result of a sql query into a variable?
java.sql.PreparedStatement preparedStatement = null;
String query = "select season from seasonTable where league_name=?";
preparedStatement = conn.prepareStatement(query);
preparedStatement.setString(1, league);
ResultSet rs = preparedStatement.executeQuery();
I need to save the retrieved season into a variable how can I do this ?
You can call
rs.next()to move the cursor for the ResultSet to the next row. That method will return a boolean indicating whether or not there actually is a next row, so you can use either anifstatement or awhileloop to retrieve the first or all of the rows returned.OR