This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes JDBC and the fly likes How does PreparedStatement.setObject() API behaves with null value? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How does PreparedStatement.setObject() API behaves with null value?" Watch "How does PreparedStatement.setObject() API behaves with null value?" New topic
Author

How does PreparedStatement.setObject() API behaves with null value?

Rashmi Tambe
Ranch Hand

Joined: Aug 07, 2001
Posts: 418
How does PreparedStatement.setObject() API behaves with null value?
For e.g. If i have

would the null passed in setObject is tranlated as SQL data type Null always? or do i have to use setNull() API?
JDBC 3.0 spec says that,

(section 13.2.2) a value must be provided (setXXX()). if the value is not set, then a SQLException should be thrown.

Is this enforced in JDBC 2.0 also? I could not get documentation abt this for JDBC 2.0...so i am doubtful.
when i run this code, it works fine sometimes. however, sometimes i get,
java.sql.SQLException: ORA-01475: must reparse cursor to change bind variable datatype
this behavior is random. so i am doubtful abt the behavior of setObject()
Can anybody exaplin this?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

Rashmi,
JDBC doesn't support setting nulls this way. dbforums has a post on this. Some drivers may support it, but it's not universal.


[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does PreparedStatement.setObject() API behaves with null value?