Search code examples
c#javacom

How can I make use of C# System.DBNull.value in Java?


I'm translating some code written in C# to Java. This code uses COM objects to interact with a third party application. I managed to handle COM objects using com4j library, but one of the methods requires System.DBNull.value to be passed into it which is a C# object.

How can I handle it from a Java application?


Solution

  • .NET System.DBNull is equivalent to a VARIANT of type VT_NULL. In fact this is documented officially here: DBNull Class

    So I suppose using com4j you can create a Variant, call setType(VT_NULL), and pass this to the .NET interop layer.