• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SQLException: Invalid column type when setting null values to NUMBER type columns

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a column in Oracle table which is of type NUMBER ( and it can be null ). Inorder to insert values , I create a PreparedStatement object and when I try to set the value for this column I get an invalid column type error. The code snippet is as below

preparedStatement.setObject ( paramIndex , args[i] ); where args[i] is null.

The result is the same with

preparedStatement.setObject ( paramIndex , null );

or preparedStatement.setNull ( paramIndex , java.sql.Types.NULL );

Can anybody tell me what could be the problem and how do I rectify the same
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NUMBER is not an object for database. It should be a number or nothing(NULL). we cant do like setObject(index, null). And you cant set 'null' in setInt() method. So, setNull() is the right method to use, but it requires the type of the column not the type of 'null'.

try this.
preparedStatement.setNull ( paramIndex , java.sql.Types.INTEGER );

cheers.
 
Ganesh Subrahmanya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Adeel. It is working now.
 
I just had the craziest dream. This tiny ad was in it.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic