Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Raghavendra ReddyI
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Paul Clapham
Sheriff
Posts: 22185
38
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
Posts: 20893
81
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?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!