I'm writing some code that uses JDBC to connect to SQL Server 7 through ODBC. I'm using getString to get the value stored in one of my nvarchar columns. I'm allowing nulls in this column. When I use getString inside of a try, I get a SQLException. I tried using wasNull to avoid the error, but I think the try prevents me from doing that. Is there some other way I can handle this? In VB, I would have used an iif statment to test the column for null, and if it is to return an empty string. [ June 27, 2002: Message edited by: Michael Brewer ]
Originally posted by Bosun Bello: Try getObject. I believe that should allow you to retrieve nulls. You can then test if it's actually null after that.
OK, getObject sounds good. I should then test for null and cast it to a String, right? The only problem is I'm not only a greenhorn on this site, but also when it comes to Java. How do I test the object for null?
The null value shouldn't be causing you problems. If you use getString() on a null column value, java transates that into a null String. So the error, if any, would be a null pointer exception. It must be incompatablility between the getString() method and your nVarchar column type. It should say in your driver documentation which method you should use to retrieve an nVarchar data type. Jamie
Originally posted by Jamie Robertson: It must be incompatablility between the getString() method and your nVarchar column type. It should say in your driver documentation which method you should use to retrieve an nVarchar data type.
Actually, I just doubled checked and the datatype is ntext. I have changed it to varchar to allow for 8000 character storage. This works. I also found that there is a bug in the JDBC ODBC driver involving ntext datatypes.