3

I cant show you my database structure... but i can try to do an example:

Table Car_Manufacturer 
(
  car_id NUMBER;
  manuFacturer_id NUMBER;
)

Values:

|TABLE CAR_MANUFACTURER   |
| CAR_ID |MANUFACTURER_ID |
|    1   |     1284       |
|    2   |    (null)      |

Select that my resultSet receives:

select * from CAR_MANUFACTURER where car_id = 2

I can get the CAR_ID:

int id = rs.get("car_id");

the output from id value:

2

But, when i try to get MANUFACTURER_ID the null value becomes an integer:

Integer manId = rs.get("manufacturer_id");

Output manId

0

Any idea? I need to get NULL value... not an integer value.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Cleiton Ribeiro
  • 359
  • 2
  • 5
  • 16

1 Answers1

5

Check the accepted answer here: How do I in JDBC read a possibly null double value from resultSet?.

It gives you a way of knowing whether the value read was null and defaulted to some value when rs.getXXX was called.

Community
  • 1
  • 1
ernest_k
  • 44,416
  • 5
  • 53
  • 99
  • 1
    If you come across a duplicate then you should flag (or close vote) as duplicate, not post an answer that is essentially pointing to the duplicate question. – Mark Rotteveel Feb 20 '16 at 15:37
  • doesnt work for me... because, when the MANUFACTURER_ID contains any value, the rs.wasNull returns TRUE. – Cleiton Ribeiro Feb 22 '16 at 13:23
  • @CleitonRibeiro The correct order of asking is `rs.getInt("MANUFACTURER_ID"); rs.wasNull();` (so immediately after getting the column value). If that doesn't work then it is a bug in the JDBC driver. – Mark Rotteveel Feb 22 '16 at 13:29
  • i'm doing exactly this way... but i'm using rs.getLong – Cleiton Ribeiro Feb 22 '16 at 13:31
  • @CleitonRibeiro That should work as well. Make sure you are using the latest version of the Oracle JDBC driver. And otherwise you may have to resort to using `getObject` instead. – Mark Rotteveel Feb 22 '16 at 13:41
  • i think... probably my jdbc driver is out of date. Because, i tried to getObject to Long variable, and doesnt work too. – Cleiton Ribeiro Feb 22 '16 at 13:50