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!
-
What is the query? What is the table? We need more infoCristian Meneses– Cristian Meneses2015年04月07日 19:34:15 +00:00Commented Apr 7, 2015 at 19:34
1 Answer 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
Eran
395k57 gold badges726 silver badges793 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default