Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating a table with doPost()

 
Sam Gill
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my doget(), i'm able to see the field values of my table, My purpose is to edit them and then post it back to the database ( updating it). here's a sample of my code In my doPost().
PrintWriter out = res.getWriter();
HttpSession session = req.getSession(true);
String passcode = req.getParameter("passcode");
Member member = new Member("passcode");
member.password = req.getParameter("password");
member.featid = req.getParameter("featid");
member.refid = req.getParameter("refid");
String s = req.getParameter("status");
member.status = Integer.parseInt(s);
......member.update();
Member class does all the updating. But wheni display my fields on the browser and then submit update.Tomcat is giving me runtime error of type:
java.lang.NullPointerException. I'm totally stuck. If you coud give me any suggestion, i would be grateful. Thanks
 
Amol Desai
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could you post the stack trace of exception along with the relevant code at which you are getting the exception
I guess one of your variables value is null.
You could just print the values to confirm that your are not getting any null value
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although it is tedious to write all those checks for null values - you will be glad you did. Since getParameter is case sensitive, all it takes is one Password instead of password to cause an error. The NPE should point to a usable line - I'm betting on the Integer.parseInt()
Bill
 
Sam Gill
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,
Thanks for your input. I checked all of my fields for null and now its working fine!!!..BUT it doesn't update the row in my database. heres my code in doPost() method:
out.println("<TR><TD align = right >");
out.println(" refid: ");
out.println("/TD");
out.println("<TD align = left >");
out.println("<INPUT type=text name=refid value="+member.refid+" >");
out.println("</TD ></TR>");
and then in doget() method:
Member member = new Member("passcode");
member.refid = req.getParameter("refid");
member.update();
Am i doing something wrong???.i have left otu tother fields..Update method basically take all the fields for specific name and then updates the database for that name
 
Amol Desai
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sam,
You need to provide some more information.
You should post the code written for the update() method.That could help us in solving your problem
 
Sam Gill
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thanks for replying...I managed to figure out the problem. I really appreciate all of ur help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic