0

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?

user207421
  • 305,947
  • 44
  • 307
  • 483

2 Answers2

2

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.

Naveen Ramawat
  • 1,425
  • 1
  • 15
  • 27
1

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.