Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ganesh Subrahmanya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks a lot Adeel. It is working now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic