1

I am getting this error in return resultset. cannot convert results from Resultset to double.

Isn't it possible to return a double? What should i do?

public double getBalance( String name )
{
 ResultSet resultSet = null;
 try 
 {
 selectBalance.setString( 1, name ); // specify last name
 // executeQuery returns ResultSet containing matching entries
 resultSet = selectBalance.executeQuery(); 
 while ( resultSet.next() )
 {
 resultSet.getDouble("balance");
 } // end while
 } // end try
 catch ( SQLException sqlException )
 {
 sqlException.printStackTrace();
 } // end catch
 return resultSet;
} 

Thx in advance!

asked Apr 7, 2015 at 19:33
1
  • What is the query? What is the table? We need more info Commented Apr 7, 2015 at 19:34

1 Answer 1

1

You should return a double if that's what you need :

public double getBalance( String name )
{
 double result = 0.0;
 ResultSet resultSet = null;
 try 
 {
 selectBalance.setString( 1, name ); // specify last name
 // executeQuery returns ResultSet containing matching entries
 resultSet = selectBalance.executeQuery(); 
 while ( resultSet.next() )
 {
 result = resultSet.getDouble("balance");
 } // end while
 } // end try
 catch ( SQLException sqlException )
 {
 sqlException.printStackTrace();
 } // end catch
 return result;
} 

Note that this would only return the value read from the last row of the result set, so if you expect multiple rows to be returned, consider returning a List<Double>.

answered Apr 7, 2015 at 19:34
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.