Well, you don't say
where the NPE happens -- the stack trace has a lot of useful information in it. But one thing I see here is that if the getConnection() method fails, it prints an exception message and returns null. Then the code that calls getConnection() fails to
test the return value for null; so if getConnection() fails, you'll get an NPE in its client code.
If getConnection() fails, the routine that calls it should fail, too, so actually, getConnection() should
not catch those exceptions; it should just let them go up and abort the caller.