GetXxxx of ResultSet was addicted to primitive type (Java)

If you get the place where NULL is entered in DB with the code of ↓, It became 0 instead of null.

Double d = rs.getDouble(1);
System.out.println(d);//"0.0"Is output

When I check it, the return value of getDouble is not Double but double ... ↓ Source ResultSet (Java Platform SE 8 )

Return value:
Column value. If the value is SQL NULL, the value returned is 0

After clarifying, the following method seems to return null other than null.

wasNull After reading with getXxxx There is also a method that can check if it is null, It's hard to use the past form instead of isNull ...

After all, it was solved with ↓

Double d = (Double)rs.getObject(1);
System.out.println(d);//Output as null

Conclusion

Don't use JDBC directly, use some kind of persistence framework.

Recommended Posts

GetXxxx of ResultSet was addicted to primitive type (Java)
I was addicted to a simple test of Jedis (Java-> Redis library)
The part I was addicted to in "Introduction to Ajax in Java Web Applications" of NetBeans
Initialization with an empty string to an instance of Java String type
[Java] To know the type information of type parameters at runtime
I was addicted to the setting of laradock + VSCode + xdebug
A story I was addicted to with implicit type conversion of ActiveRecord during unit testing
I was addicted to starting sbt
[Java] Input to stdin of Process
Android memo-I was addicted to Permission
[Java] Correct comparison of String type
I was addicted to the API version min23 setting of registerTorchCallback
How to use Java enum type
A memo that was soberly addicted to the request of multipart / form-data
[CircleCI] I was addicted to the automatic test of CircleCI (rails + mysql) [Memo]
From Java9, the constructor of the class corresponding to primitive types is deprecated.
I was addicted to rewriting to @SpringApplicationConfiguration-> @SpringBootTest
I was addicted to the roll method
[Java] [Maven3] Summary of how to use Maven3
I was addicted to the Spring-Batch test
[Basic knowledge of Java] About type conversion
Output of the book "Introduction to Java"
[Java] Comparison of String type character strings
Java Summary of frequently searched type conversions
Type conversion from java BigDecimal type to String type
[Java] How to convert one element of a String type array to an Int type
Summary of points I was worried about when migrating from java to kotlin
Use jenv to enable multiple versions of Java
I was addicted to using RXTX on Sierra
[java] Summary of how to handle character strings
A story addicted to EntityNotFoundException of getOne of JpaRepository
Things to be aware of when writing Java
[Introduction to Java] About type conversion (cast, promotion)
[Java] Summary of how to abbreviate lambda expressions
[Java] Be careful of the key type of Map
I was addicted to installing Ruby/Tk on MacOS
I was addicted to doing onActivityResult () with DialogFragment
[Java] char type can be cast to int type
[Java] How to get the authority of the folder
[Introduction to Java] Basics of java arithmetic (for beginners)
Java review ③ (Basic usage of arrays / reference type)
Java Welcome to the Swamp of 2D Arrays
A memorandum because I was addicted to the setting of the Android project of IntelliJ IDEA