using setObject when object set is Null throws Invalid column Type Exceptio
priyarunAug 17 2004 — edited Aug 18 2004I 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.