wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Updating a table with doPost()" Watch "Updating a table with doPost()" New topic

Updating a table with doPost()

Sam Gill

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 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
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

Joined: Mar 22, 2000
Posts: 12761
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()
Sam Gill

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 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");
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

Joined: Jun 06, 2003
Posts: 8
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()
Similar Threads
JDBC code with type 1 driver not working
J2EE server not connecting to database
making user enter the parameter of field in doGET