Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can we use PrepareStatement for deleting?

 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I think answer to this question should be yes
but when I am using it and calling the update function from my jsp
it do not seem to work
As far as I think this syntax is correct
void update()
{
PreparedStatement pstmt = con.prepareStatement("delete from table where colname= ?");
pstmt.clearParameters();
pstmt.setString(value_from_jsp);
pstmt.executeUpdate();
con.commit();
}
Correct me anyone if I am wrong?
 
Raja Shekhar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gaurav..
The Syntax is wrong...
here
pstmt.setString(value_from_jsp);
change it to
pstmt.setString(1,value_from_jsp);
bye
Raj
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!