Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a Double out of a resultset instead of double?

Tags:

When working with a JDBC resultset I want to get Double instead of double since this column is nullable. Rs.getDouble returns 0.0 when the column is null.

like image 316
benstpierre Avatar asked Jan 28 '10 21:01

benstpierre


People also ask

What is the use of wasNull () in ResultSet interface?

The wasNull() method of the ResultSet interface determines whether the last column read had a Null value. i.e. whenever you read the contents of a column of the ResultSet using the getter methods (getInt(), getString etc...) you can determine whether it (column) contains null values, using the wasNull() method.

What is ResultSet next ()?

The next() method of the ResultSet interface moves the pointer of the current (ResultSet) object to the next row, from the current position. Statement stmt = con. createStatement(); ResultSet rs = stmt.

How do you traverse ResultSet?

Iterating the ResultSet To iterate the ResultSet you use its next() method. The next() method returns true if the ResultSet has a next record, and moves the ResultSet to point to the next record. If there were no more records, next() returns false, and you can no longer.


1 Answers

You can check for wasNull on your ResultSet to find out if the value was null.

Note that you must first call one of the getter methods on a column to try to read its value and then call the method wasNull to see if the value read was SQL NULL.

If you really need a Double afterwards, you can create it from the double returned.

like image 119
Peter Lang Avatar answered Oct 13 '22 22:10

Peter Lang