Can one get null
value using the ResultSet.getShort()
method in java?
I know that it converts null
value to 0
,and we can use the getObject()
method to check null
values, but can one get null
values using the getShort
method?

- 305,947
- 44
- 307
- 483

- 1
- 1
-
Of course not. How can a `short` be null? – user207421 Mar 06 '14 at 04:17
2 Answers
You could check that last fetched value was null or not using the resultset method wasNull(). If it was true you can consider your getShort() value is null instead of 0 in your business logic.

- 1,425
- 1
- 15
- 27
short getShort(String columnLabel) throws SQLException
Retrieves the value of the designated column in the current row of this ResultSet object as a short in the Java programming language.
Parameters: columnLabel - the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
Returns: the column value; if the value is SQL NULL, the value returned is 0
Throws: SQLException - if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
Oracle Reference: http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet.html#getShort(java.lang.String)
So your answer is no, you can't get null from the getShort method.

- 90
- 3