This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes This servlet code is executed but cannot insert data into database .Iam using oracle database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "This servlet code is executed but cannot insert data into database .Iam using oracle database" Watch "This servlet code is executed but cannot insert data into database .Iam using oracle database" New topic
Author

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

Raghavendra ReddyI
Greenhorn

Joined: Sep 10, 2012
Posts: 8
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8



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

Joined: Oct 27, 2005
Posts: 19654
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Raghavendra ReddyI
Greenhorn

Joined: Sep 10, 2012
Posts: 8
can i knw how to execute multiple queries using single connection?
 
 
subject: This servlet code is executed but cannot insert data into database .Iam using oracle database
 
Similar Threads
stylesheet effect are not showing in jsp page
update of records
Help ME PLZ. Very Soon..
Trouble with "@" and spaces in mySQL
Absolute Position in IE