Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting null using setInt

 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic