• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Update Code

 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Throws Following Exception

 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Check Line 46 in your servlet. "ad" is not initialized and hence the NullPointer.

Regards,
Amit
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey great your idea worked...!! now it leads me to the blank page.

 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's because the boolean expression in line 29 can only be false, and so the "forward" is never done.
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Well, that's because the boolean expression in line 29 can only be false, and so the "forward" is never done.


Well am sorry but some more clarification I need please cause am already new to this.! Please help me!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carefully check what you are comparing on line 29. Are you really comparing what you think you are comparing? If all else fails, use print statements to see the values. Learning to debug is a skill you must acquire if you are going to be writing this level of code.
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Carefully check what you are comparing on line 29. Are you really comparing what you think you are comparing? If all else fails, use print statements to see the values. Learning to debug is a skill you must acquire if you are going to be writing this level of code.


Sir please have a look at this code



In this the very first text field will contain the the value of current password & what I'm trying to check is if the fetched value is which is stored in sql1 variable is equal then it should update the password. Also you are correct that I have never written this level of code. But if you suggest me something that will really be helpful to me. Thanks a lot.

I still need to know what changes should be made to my code please.




 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use print statements just before line 29 to check what you are comparing, as I already suggested. I'm not going to give you code. You need to learn how to diagnose problems in your own code.

Bonus hint: does sql1 really contain what you think it contains?
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Use print statements just before line 29 to check what you are comparing, as I already suggested. I'm not going to give you code. You need to learn how to diagnose problems in your own code.

Bonus hint: does sql1 really contain what you think it contains?


hey yes i did got an idea about it but i dint dare to touch it like that...!! let me try it....thanks alot
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh my God...!!! you are amazing...!! it printed this

select pass from staff where pass = admin1

Just super liked your solution...!! thanks a ton...!!!
let me try something else. And I'll get back to you cause I know I'd need help again...well thanks a ton anyway
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To quote a great Jedi: "You have taken your first step into a larger world."
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey now I made changes to my code and changed it as below


its not updating the database but does redirect to the home page and shows username as Welcome, null

any suggestions please?
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:To quote a great Jedi: "You have taken your first step into a larger world."


Well trust me if I have your support when I need I'll win this battle.!!
I promise you try myself but where I end up...I'd need your help :O
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It cannot be redirecting because you have no redirects in your code; you have forwards. Forwards are not the same as redirects so it's important not to confuse them with each other.

If you want data to be available to the JSP you are forwarding to, you must create scoped variables in request scope (using setAttribute() on the request instance). Then these scoped variables can be accessed on the JSP via the EL.

Be sure that your JSP is using the JSTL and EL and not obsolete Java scriptlets.
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It cannot be redirecting

Its being redirected but not updating the table records
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, no it's not. It's being forwarded. A forward is not a redirect.

In any case, that's independent of the database update. If that's not working, then your database code isn't succeeding. That's a JDBC issue.

My suggestion: move the database code out of the servlet and into its own independent class. It'll be easier to test (you can even write a command line program to test it) and is a better design than mixing database code into user interface code.

Check to see if an exception is being thrown.
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Again, no it's not. It's being forwarded. A forward is not a redirect.

In any case, that's independent of the database update. If that's not working, then your database code isn't succeeding. That's a JDBC issue.

My suggestion: move the database code out of the servlet and into its own independent class. It'll be easier to test (you can even write a command line program to test it) and is a better design than mixing database code into user interface code.

Check to see if an exception is being thrown.



hmm well am sorry am asking too many questions
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who said that?
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there this is how I changed the code now..!!




its going on another page but not actually updating the database what's the problem. Please Suggest..!!
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that would be because your update statement doesn't find any rows to update. Have a look at the parameters of your SQL update statement, and then look at the variables you assign to them.

And by the way, in this statement here:



Could you explain when you think the body of this if-statement would NOT be executed?
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resolved...!! Its working now...!! Thanks All for my help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic