0

I have a piece of code along the following lines:

Properties props = new Properties();
props.put("user", user.getUserName());
props.put("password", user.getPassword());
//add more properties
//...
Connection conn = DriverManager.getConnection("url",props);

So, there is no way that I can see that a null password property can be passed into the connection. Not only does user.getPassword() throw an exception if the password is null, setting a null value on props would throw an NPE. Either of this will cause the call to DriverManager.getConnection(..) to be bypassed. Yet on occasion, the connection attempt fails and Oracle returns an

ORA-01005 ORA-01005: null password given; logon denied

The only way I can recreate this on demand is by commenting out the line that sets the password. Otherwise I can't see how a null value is getting to Oracle.

Could it be that there are some values that Oracle reports to be null that are not strict Java nulls?

I'm using oracle.jdbc.OracleDriver to connect to Oracle 11.2.0.3.0

Many thanks for any help!

user987339
  • 10,519
  • 8
  • 40
  • 45
elgaz
  • 121
  • 2
  • 9
  • Have you tried using an empty string? – Jon Skeet Dec 11 '13 at 14:02
  • possible duplicate of [Why does Oracle 9i treat an empty string as NULL?](http://stackoverflow.com/questions/203493/why-does-oracle-9i-treat-an-empty-string-as-null) – Keppil Dec 11 '13 at 14:07
  • Try debugging your code using: System.out.println("user: >" + user.getUserName() + "<, password: >" + user.getPassword() + "<"). NULL in oracle means "no value", which includes empty strings. – DwB Dec 11 '13 at 14:21

2 Answers2

3

I think the Oracle jdbc driver considers the empty string to be equivalent to NULL.

DaveH
  • 7,187
  • 5
  • 32
  • 53
3

Oracle database differs from Java in this sense. It treats String empty values as null. See also Oracle treating empty string as NULL problem for a Java / JPA programmer

Community
  • 1
  • 1
Mohammad Banisaeid
  • 2,376
  • 27
  • 35