File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Updating a table with doPost() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Updating a table with doPost()" Watch "Updating a table with doPost()" New topic
Author

Updating a table with doPost()

Sam Gill
Greenhorn

Joined: Jun 06, 2003
Posts: 8
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

Joined: Jan 29, 2003
Posts: 82
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

Joined: Mar 22, 2000
Posts: 12769
    
    5
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

Joined: Jun 06, 2003
Posts: 8
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

Joined: Jan 29, 2003
Posts: 82
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

Joined: Jun 06, 2003
Posts: 8
Hello,
Thanks for replying...I managed to figure out the problem. I really appreciate all of ur help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Updating a table with doPost()