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 Inserting null using setInt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Inserting null using setInt" Watch "Inserting null using setInt" New topic
Author

Inserting null using setInt

Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Hello,
I am trying to load some data into Oracle using JDBC. One of the fields is of type integer. There are instances that the data may be null.
When I manually execute "INSERT INTO .." statement I was able to load a null value to integer field, but not through 'setInt' method.
Can anyone shed some light on this?
Thanks
Suresh
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Suresh
I assume your talking about in a PreparedStatement? You'll need to use the setNull method. I guess it is the same philosophy as testing a ResultSet for null, since it is a special vlaue it is handled separatley.
hope that helps


Dave
Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Hi Dave,
When I try to run the line
"ps.setNull (5, java.lang.Types.INTEGER)"
I am getting "java.lang.NumberFormatException" message.
I am using JDK1.1.8.
Any thoughs?
Thanks
Suresh
Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Dave,
I found the error. When I checked the Oracle site, according to Oracle I need to use 'OracleTypes.NUMBER' for JDK 1.1.x.
And it works.
Thanks
Suresh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting null using setInt