| Author |
Difficulty in Updating database
|
renu richard
Ranch Hand
Joined: Oct 06, 2008
Posts: 116
|
|
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...
|
Cheers,
Richard
|
 |
rakesh sugirtharaj
Ranch Hand
Joined: Dec 16, 2007
Posts: 151
|
|
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.
|
Cheers!
RSR
|
 |
rakesh sugirtharaj
Ranch Hand
Joined: Dec 16, 2007
Posts: 151
|
|
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
Joined: Oct 14, 2008
Posts: 12
|
|
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
Joined: Oct 06, 2008
Posts: 116
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
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.
|
 |
 |
|
|
subject: Difficulty in Updating database
|
|
|