Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.NullPointerException

 
syed taha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings to all java lovers,
i am just fell in love with java and start working on it but getting some problems,
I think this is easy problem but i couldn't find where it goes wrong....this is jdbc program with callable statements(IN),i had created two tables with name bank and personal_details and a procedure "createaccount"
but that procedure is created with compilation errors....



 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Syed,

Welcome to Ranch!

Please use code tags while posting code in your post. This makes easier to read.

Thanks,
Prajakta
 
Campbell Ritchie
Sheriff
Posts: 51436
87
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added code tags since the OP is new. You can see how much better it looks . You cannot use [u] tags or similar inside code tags.
 
syed taha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CAN ANYONE HELP ME TO TAKE OUT FROM THIS PROBLEM?........IM STRUCK HERE....
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to shout!

If you're getting a NullPointerException, then it will tell you exactly which line that is happening on. In general if you tell us which line that is, then we'll be in a much better position to help.

There's one obvious problem at the moment, though. You never initialise the variable con. You open a connection...and do nothing with it.

Another potential issue is that if there's a problem opening the connection, because of the way you've arranged the try/catch you print out the stack trace and then go ahead and try to run a query anyway, which is unlikely to be what you need.
 
syed taha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i click the this Exception in thread "main" java.lang.NullPointerException
at com.practice.jdbc.CallableDemo.main(CallableDemo.java:41)


it takes me here "CallableStatement cs=con.prepareCall("{ createaccount(?,?,?,?,?,?)}");"
 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I can see from your code is that, the con variable is not assigned the connection obtained from the DriverManager. 'con' is null and some operations are performed on it.
This will result in NullPointerException.
 
Green Onyeji
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Substitute 'DriverManager.getConnection(your url, username, password);' with 'con = DriverManager.getConnection(your url, username, password);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic