Answer the question
In order to leave comments, you need to log in
Request by id does not produce a result?
Hello, I'm making a request to return a field by its id, but it does not return a result, but if I request to display all the fields, then everything is ok.
public Student getById(int id) {
Student student = new Student();
PreparedStatement preparedStatement = null;
String sql = "SELECT * FROM stud WHERE id=?";
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, id);
ResultSet resultSet = preparedStatement.executeQuery();
student.setId(resultSet.getInt("id"));
student.setFirstName(resultSet.getString("first_name"));
student.setSecondName(resultSet.getString("second_name"));
student.setCourse(resultSet.getInt("course"));
preparedStatement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
return student;
}
Answer the question
In order to leave comments, you need to log in
....
ResultSet resultSet = preparedStatement.executeQuery();
resultSet.first();
....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question