I have this method to insert data using jdbc that will insert the value according to the java type. Something like this:
Object o = map.get( key );
if( o == null ) {
// setNull( index );
} else if( o instanceof String ) {
// setString( index, (String) o );
} else if( o instanceof Timestamp ) {
// setTimestampt( index, ( Timestamp ) o );
} else if( o instanceof Integer ) {
// setInt( index, (Integer) o );
}
index++;
It has a problem though ( beside it is all commented :P )
If the value of o is null, I'm requiered to use "setNull(int, int)" method, but I have to specify the SQL type:
...Note: You must specify the parameter's SQL type.
But... I don't know the type, so I'm considering use always VARCHAR ( just because )
setNull( index,Types.VARCHAR); .
What would happen if I set null in prepared statement with varchar always?
I'm using:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
With Oracle JDB driver:
11.1.0.7.0-Production ( ojdbc6.jar )
What would be an alternative?