File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Types.OTHER confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Types.OTHER confusion" Watch "Types.OTHER confusion" New topic

Types.OTHER confusion

Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
Hi all,
I have a Preparedstatement with a single ? in it.
For that ? I am doing a
It throws me a exception at this line saying
"cannot Insert NULL......."
The table col in the db is of type varchar2 and does not have a NOT NULL
constraint on it.
Now if I change this line to
then it passes properly.
Why is it so?
What is it about Types.OTHER that prevents me from setting it to NULL.
I am using Oracle 9i as the backend db.

The strength of the Wolf is the pack & the strength of the pack is the wolf....Rudyard Kipling
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
When using the "setNull(...)" method on a PreparedStatement instance, you need to make sure that the type you send in as the second parameter matches the column type in Oracle. In the Oracle documentation (I looked in the 9i PDF from Oracle) they list the datatype mappings, and nowhere on the list do I see "java.sql.Types.OTHER. This may mean it is not supported in Oracle.
But in any case, if the underlying Oracle column is "varchar2", then you most certainly need to use something like "java.sql.Types.VARCHAR" as the second parameter of your "setNull(...)" call.
If you tried to use "java.sql.Types.INT" or "java.sql.Types.TIMESTAMP" in place of "java.sql.Types.OTHER" you'd probably get the same error. The types have to match.
Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
Thanks Wayne,
Things are more clearer.
Can u give me the link to the PDF you referred.....??
Thanks again,
It is sorta covered in the JavaRanch Style Guide.
subject: Types.OTHER confusion
It's not a secret anymore!