• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NPE for sql Connection

 
Padmanabh Sahasrabudhe
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is making me mad
I have the following code for Connection:



I am getting NPE at second System.out.println(connection.toString()); statement and not at first. Not sure why?

I tried changing the driver to oracle.jdbc.OracleDriver but in vain!
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's suppose an exception is thrown before a value is assigned to the "connection" variable. You catch that exception and print a message. Then you carry on and try to use the "connection" variable, which is still null.

As you imply, the real problem is something else, namely something to do with loading the driver class. Your code printed the exception, which you didn't share with us. So read it and act accordingly.
 
Padmanabh Sahasrabudhe
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. This is the exception I ma getting. It doesn't seem that problem with loading driver. I get the value of the drive printed in the output.

oracle.jdbc.driver.OracleDriver
java.lang.NullPointerException
at tests.functional.cartridge.spatial.common.apps.spatial_cartridge.SpatialDBHelper.getJDBCConnection(SpatialDBHelper.java:53)
at tests.functional.cartridge.spatial.common.apps.spatial_cartridge.SpatialDBHelper.main(SpatialDBHelper.java:24)

 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I don't know why you would choose to print only that. Your next catch block prints the entire stack trace, which would have been far more useful.
 
Padmanabh Sahasrabudhe
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you are right. it was a classpath issue for the driver and it was not loading. thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic