Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

database not getting updated

 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Above is the code to create aservlet which fetch data from given form and update the MYsql database.
It compiled and run without any error but database not getting updated
 
Tim Moores
Bartender
Posts: 3134
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You realize that this code is wide open to SQL injection attacks, right? Start by learning about PreparedStatement; it's been available forever, and the internet is a dangerous place.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a question what value is flag after the insert? as this is the number of rows inserted.

and just to let you know about future problems you should have a finally block where you close the connection, and the statement.
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
flag don't showing any value. Niether the database is showing any updation.
 
Swastik Dey
Rancher
Posts: 1639
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As suggested by Tim use PreparedStatement. As far as the this code is concerned, print the exception stack trace and see if it says something.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the init() method to initialize the database resources, and destroy() method to close the connection.

As suggested, go for the PreparedStatement
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the suggestion, will try if it works.
 
Punit Jain
Ranch Hand
Posts: 1016
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for me your code is working properly..
try to execute your same query in mysql query browse and check weather it executes or not.
and as everyone suggested use preparedstatement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic