File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes how to pass a NULL parameter in prepareCall method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to pass a NULL parameter in prepareCall method." Watch "how to pass a NULL parameter in prepareCall method." New topic
Author

how to pass a NULL parameter in prepareCall method.

Pooja Agarwal
Ranch Hand

Joined: May 19, 2004
Posts: 37
Hai All

I have got a problem in invoking a stored procedure from java code,

The Java code is:
-----------------

cstmt = connection.prepareCall("{call INSERTUPSDEMO(?, ?, ?, ?, ?)}");

cstmt.setString(1, "SAM");
cstmt.setInt(2, 2000);
cstmt.setInt(3, 250);
cstmt.setInt(4, 3467);

cstmt.registerOutParameter (5, Types.INTEGER);
cstmt.execute();
temp = cstmt.getInt(5); // Get the output parameter values

My Problem:
-----------

The code works fine if i give all the parameters.
But in some cases i may not pass all the parameters,
for example if i dont want to send the parameter4 value,
i.e i want to send a null value into it.
I need to know how to pass a null parameter.


Any help is appreciated,
Thanks in advance,
Pooja
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Pooja,
You need to call setNull(). Sun has a section in their tutorial on this.


[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
Pooja Agarwal
Ranch Hand

Joined: May 19, 2004
Posts: 37
Hai Jeanne,

Thanks a lot for ur help.
It worked fine with setNull() method.

Thanks once again,
Pooja.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to pass a NULL parameter in prepareCall method.