0

So I am trying to execute a query that takes 2 int values from the user however I am getting this error message. What I am doing wrong?

"at least one parameter to the current statement is uninitialized"

This is my Query

selectStudentsInRange = connection.prepareStatement("SELECT* FROM Results WHERE total BETWEEN ? AND ?"); 

An this is my method, yes is not the whole code.

public List< Results > getTotalMarksInRange( int value1, int value2 )
 {
  List< Results > results = null;
  ResultSet resultSet = null;

  try 
  {
      selectStudentsInRange.setInt( value1, value2 ); // specify id

     // executeQuery returns ResultSet containing matching entries
     resultSet =  selectStudentsInRange.executeQuery(); 

     results = new ArrayList< Results >();

Please notice that this is not the whole code I have many classes I am just wondering what is my error in this part.

3 Answers 3

2

at least one parameter to the current statement is uninitialized

selectStudentsInRange.setInt( value1, value2 ); // specify id

Change to

selectStudentsInRange.setInt(1, value1 ); 
selectStudentsInRange.setInt(2, value2 ); 
Sign up to request clarification or add additional context in comments.

Comments

1

That should be:

selectStudentsInRange.setInt(1, value1);
selectStudentsInRange.setInt(2, value2);

The first argument is the parameter index, the second argument is the parameter value.

See the documentation here.

Comments

-1

Take a look to this Parameters For-PreparedStatement

selectStudentsInRange.setInt(1, value1 ); //this is how to set First Argument.
selectStudentsInRange.setInt(2, value2 )  // Set Your Second Argument.
//but make sure value1 and value2 both are Integer Type

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.