This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

This servlet code is executed but cannot insert data into database .Iam using oracle database

 
Raghavendra ReddyI
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Paul Clapham
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This isn't the right way to compare whether two String objects have the same contents. Use the equals() method of String to do that:



If you do some basic debugging I think you'll find that none of your JDBC code is ever executed.

 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the HTML outputting inside the servlet, I see three major issues, where the third one is the probable cause of your direct issue:
1) You shouldn't ignore the exception in the init method. At least print it, so it will be present in the logs. Or just wrap it in a ServletException so the servlet will fail to initialize.
2) Your code is prone to SQL injection. Use a PreparedStatement instead.
3) Don't compare Strings using == but use the equals method instead. You're comparing for instance equality, and it's very unlikely that the parameter value is exactly the same object.
 
Raghavendra ReddyI
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i knw how to execute multiple queries using single connection?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic