aspose 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
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29257
    
140

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.
 
Similar Threads
Cannot set attribute in request in jsp
MS SQL Server and Java...
Passing Parameters to Child window
Ordinal binding and Named binding cannot be combined!
CallableStatement problem