Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
A Java variable that holds a reference to an object can hold a nullvalue. But a primitive data type such as an int or a double can't hold a nullvalue. So when you retrieve a null value into a primitive data type, the value retrieved is set to 0. However, you can use the method wasNull() of the ResultSet interface to check if the value you retrieved was a null or not. 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 null or not:
public boolean wasNull() throws SQLException;
Similarly, to set any column value to null, you can use the setNull() method of the PreparedStatement interface, which also takes in the SQL type of the column as the second parameter: