This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes How to skip a parameter for Prepared Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to skip a parameter for Prepared Statement" Watch "How to skip a parameter for Prepared Statement" New topic
Author

How to skip a parameter for Prepared Statement

Manu Ramakrishnan
Greenhorn

Joined: Jun 07, 2003
Posts: 10
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

Joined: Jan 27, 2004
Posts: 202
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

Joined: May 26, 2003
Posts: 32481
    
214

Billy is right. You can create a new statement without the description parameter to get around the problem.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
Why cant u do a setNull() for the first param??
Let us know if that works for you???
Thanks,
Chinmay


The strength of the Wolf is the pack & the strength of the pack is the wolf....Rudyard Kipling
Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
Plzz ignore my prev post...
I didnt understnd ur Q properly.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: How to skip a parameter for Prepared Statement
 
It's not a secret anymore!