This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null pointer exceptiion

 
jyotsana dang
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is null pointer exception ? And how do we rectify it? I have written a JSP code for inserting values to a database. But Iam getting a null pointer exception for the same..
 
Natraj Gudla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When ever a "null" is used when an object is required, a NullPointerException is thrown.
To avoid this we need to be careful while assiging object references and creating structures.Explicit check on the null references before they are used can avoid such exceptions.
 
Natraj Gudla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry..a correction...it is a null not a string "null".
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jyotsana ,
NullPointerEception is thrown whenever you use dot(.) with and variable which is object and contains null value.
say you have String s=null;
and you say s.substring(); this is same as null.substring(); which throws an nullpointer exception.
In your case I guess you are getting null pointer exception during creating connection.
just chek if your connection object is not null before createing statment like..stmt=con.createStatement();
Cheers
Praful
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a JSP concept. Moving this to the Java in General(beginner) forum.
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic