*
The moose likes JDBC 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30070
    
149

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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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 agree. Here's the link: http://aspose.com/file-tools
 
subject: How to skip a parameter for Prepared Statement
 
Similar Threads
Why Servlet return a blank page?
wildcard search
PreparedStatement issue
Solved : How delete oldest records
To store multiple data in ResultSet