Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem accessing two tables from servlet

 
deepak borole
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to update a table from few tables using executeUpdate() from a servlet....from the previous page i am selecting the table to be updated and then in the servlet using if and else if i hav written code to update the table but only one table is getting updated...the code written in else if is not working means the executeUpdate() is not working....what must be the problem.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do get the table names in your servlet ? getParameter ?
How do you select the tables ? Please give us some clues
 
deepak borole
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have taken hardcoded string in which table names are there like ...
insert into tablename values(?,?,?,?)......but the executeUpdate() is not working.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using the same variable for the tablename, it will match only one "if" !



If you are doing this, it will only match one branch.

It is difficult to imagine what you are realy doing without seeing a bit of code.
 
deepak borole
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya it will match only one if....
if(subject.equals("mechanical"))
{
....
....
i = p_stmt.executeUpdate();
}
else if(subject.equals("electrical"))
{
....
....
i = p_stmt1.executeUpdate();
}
now what is happenin is that if mechanical is selected then it is going in the if loop and updating the table but if electrical is selected it does not execute the executeUpdate()....here different tables are updated when in any of the if loops i.e. if in mechanical then mechanical table is updated n so on....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic