GeeCON Prague 2014*
The moose likes JDBC and the fly likes SQLException: Invalid column type when setting null values to NUMBER type columns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQLException: Invalid column type when setting null values to NUMBER type columns" Watch "SQLException: Invalid column type when setting null values to NUMBER type columns" New topic
Author

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

Ganesh Subrahmanya
Greenhorn

Joined: Feb 19, 2004
Posts: 4
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Feb 19, 2004
Posts: 4
Thanks a lot Adeel. It is working now.
 
 
subject: SQLException: Invalid column type when setting null values to NUMBER type columns