• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difficulty in Updating database  RSS feed

 
renu richard
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to JSP. Actually i am getting the inputs from the user in the login.jsp. Then i am updating that values in the database using SQL query an then reading those values(which was written to database) and then setting it to an attribute and passing it to another JSP which displys the
datas.
But when trying to do so, i am getting the below error. Please help me on this. Many Thanks!!


Error message :
java.lang.NullPointerException
com.example.Sample.doPost(Sample.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
*************************************************************************
When i checked it in database it is not updated. Please let me know if there is anything wrong with the code. Thanks...
 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Renu,

Read the exception trace - It says -

There is a null pointer exception in line number 33 in Sample.java.
So find out what is there in line number 33.
 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is with the statement stmt object because you are using the stmt object from another try/catch. Put a single try with appropriate catches and it should work fine.

And one more, you dont need PrintWriter for response when you are forwarding to a different page.
 
sujith delpachithra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stmt.executeUpdate("insert into Employee(EMP_ID,FIRSTNAME) values("+name+","+empid+")");

this should be change as
stmt.executeUpdate("insert into Employee(EMP_ID,FIRSTNAME) values('"+name+"','"+empid+"')");

because you are using string.
try this
 
renu richard
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Now i am getting the value as null. And there are nothing inserted in to the table. How can i ensure that the connection is established? so that i can confirm that the problem is only when trying to insert.
[ October 30, 2008: Message edited by: renu richard ]
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need all sorts of print statements, and you need to divide that application into parts. Comment out the second try-catch and see what happens with the INSERT part only.

Insert this sort of statement at strategic points throughout the code:

System.err.printf("Line 834685: The connection exists: %b ", con != null);//test
System.err.printf("Line 837458: So does the statement: %b%n", stmt != null);//test

See when you start getting falses, that will give a hint where the problem occurs. I presume you have used **** to obscure the URL in the code you are posting.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!