Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

using setObject when object set is Null throws Invalid column Type Exceptio

priyarunAug 17 2004 — edited Aug 18 2004
I would like to insert 'null' into a numeric column in Oracle (the column does allow null fields)

PreparedStatement ps ....
// The setObject(...) doesnt work, "Invalid column type" error is returned
ps.setObject( idx2col, null );

The following code works:
ps.setNull( idx2col, Types.INTEGER );

The problem with the above code is that it requires that I know the type of the field the object will be going into. I do not know this information because the code that executes this PreparedStatement is very general. Sometimes the column that will be set to null is a number, sometimes its a string or date...

Does anyone have suggestions as to how a null can be inserted into the column without knowing the type (Using Oracle + their thin jdbc driver)?

Few of my reasearch

1. If I use ps.setNull( idx2col, Types.VARCHAR )
It works for Numeric, Date and varchar . But I don't think this is the right way. And it may create some unforseen error in future.
2. If I use
pstmt.setNull(parameterIndex, pstmt.getParameterMetaData().getParameterType(parameterIndex));

It throws error "Feature Not supported"
We are using the oracle thin driver. (I don't know the version). I guess it will always call setObject on OraclePreparedSatement. I saw it source code after decompling and saw

public OracleParameterMetaData OracleGetParameterMetaData()
throws SQLException
{
DBError.throwUnsupportedFeatureSqlException();
return null;
}



Would appreciate any help. But I am in hurry because I need to implement in current project.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 15 2004
Added on Aug 17 2004
5 comments
1,820 views