Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to skip a parameter for Prepared Statement

 
Manu Ramakrishnan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
My issue is that I want to skip the updation of one parameter, without getting an exception.
I am not setting the first parameter.Here is the code snippet. Can anyone please help ?
con=ConnectionManager.getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE GIFI SET DESCRIPTION=?,TYPE=? WHERE ACCNO=?");
ps.setString(2, "CHEQUE");
ps.setString(3, "1000");
System.out.println(ps.execute());
Thanks
Manu
 
Billybob Marshall
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't make sense to skip a parameter, as the resulting SQL would look something like this:
UPDATE GIFI SET DESCRIPTION=?,TYPE='CHEQUE' WHERE ACCNO='1000'
Don't you see the problem with the bad resulting SQL?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Billy is right. You can create a new statement without the description parameter to get around the problem.
 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why cant u do a setNull() for the first param??
Let us know if that works for you???
Thanks,
Chinmay
 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plzz ignore my prev post...
I didnt understnd ur Q properly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic