Categories
Java SQL Server

Sending null values as parameters into a SQLServer stored procedure using JDBC

When calling a SQL Server stored procedure using JDBC’s CallableStatement object one uses its setXXX methods to set input parameters. XXX is the name of the type the input parameter is assumed to be of.
SQL Server does not support the setNull() method, throwing this exception:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC] The specified SQL type is not supported by this driver.

One way we went around this unpleasantry was to instead set the null value to be a different type, so instead of
setNull(position, variable)

There is an entry in the SQL Server JDBC newsgroup about this issue.
we create a new null String object and then call:
setString(position, nullString)

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Share