• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Problem in updating the fields to database

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to display records then onclick edit button the fileds will edit then update button , onclick this button the database shd update with the fields, I am getting NullPointer Exception, Dont knw wats the problem, Here is my code

OutransEdit.java



The Dt_of_OUT_Transaction column is VARCHAR2(20).


This code is giving me NullPointer Exception, Can anyone please look into my code and correct, Its urgent. I really dont knw where is the problem. Please help me out.

Thanks in advance
Lissy.
 
Ranch Hand
Posts: 144
Oracle Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems like it belongs better in the JDBC forum. With that being said, I have a few comments about your code.

When you are asking people to help solve a problem, it is nice and sometime necessary to provide the stack trace. There are a lot of things in your code that could be causing errors. The most likely problem is the is a problem with your setting of values from your request. Request parameters are ALWAYS Strings. Your use of toString() could be causing the NullPointer if the parameter does not exist. Have you verified that all the request parameters are being set? Try writing all the Strings to a log to see what their values are being set as.

Whenever you are performing a database update, ALWAYS USE java.sql.PreparedStatement. Using regular java.sql.Statement leaves your application open for SQL injection attacks. You may not want to have your request parameters exactly match the names of the fields in your table. That makes it even easier to perform the SQL injection. You should also sanitize any inputs for not only SQL injection, but also to prevent simple formatting issues. Do you verify that all the request parameters are of the proper type and length? Do any varchars exceed the length of the database field?

Your database structure should also be in the Third Normal Form. The way you have your table structured defeats the purpose of having a database since it acts more like a spreadsheet. Is there a reason that your Inventory_Qty field is stored as a varchar instead of a numeric type?

A minor coding point, but a rule of thumb is not to have a single line of code exceed the width of the screen. You should add some line breaks into your SQL query string.
 
Master Rancher
Posts: 1988
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which line is showing npe? And it would be better to use PreparedStatement instead of Statement.
 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the JDBC forum.
 
Sheriff
Posts: 24633
56
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:Which line is showing npe?



I predict it's going to be one of the lines like

where request.getParameter("Inventory_Qty") is returning null (because the user didn't fill in that box in the HTML form).
 
lisy jessica
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot for the quick responses,

The full stack trace is




I am still getting the same error, The problem was with Inventory_Qty, The datatype of Inventory_Qty is Number, now I removed this Inventory_Qty from my code and trying to update other fields using prepared statement, am still getting the above error. Please help me out. I am really confused y am getting still getting the error.

Thanks in advance
Lissy.
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Well the exception says it is happening on line 31 of that class:

java.lang.NullPointerException
at update.OutEditData.doPost(OutEditData.java:31)

which in the code you posted is this line: Have you followed Mike's advice above and printed out the value of each of the parameters (and also not called the toString() method) like:
Also another code style thing, variables typically start with a lower case letter to make it easier for someone reading the code to know what is a class and what is a variable.

Sean
 
lisy jessica
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for the prompt reply, will try this and get back to you.


Thanks,
Lissy.
 
lisy jessica
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have printed the values, two values are returning null thats y am getting NullPointerException, the values are Requested_By, Issued_By

this is my EditServlet.java



OutEditData.jsp




I dont know y the two values are null, Requested_By and Issued_By, Please can anyone look into my code and correct me.

Thanks in advance
Lissy.
 
lisy jessica
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot everyone for helping me, I got it finally, I made a silly mistake, I gave a space after the Requested_By and Issued_By that's y am getting NPE.

String Requested_By = request.getParameter("Requested_By ");

String Issued_By = request.getParameter("Issued_By ");


Thanks alot everypone once again for helping me.

Thanks
Lissy.
 
You didn't tell me he was so big. Unlike this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!