Using Parameter Metadata
Collapse the table of content
Expand the table of content

Using Parameter Metadata


To query a SQLServerPreparedStatement or a SQLServerCallableStatement object about the parameters that they contain, the Microsoft JDBC Driver for SQL Server implements the SQLServerParameterMetaData class. This class contains numerous fields and methods that return information in the form of a single value.

To create a SQLServerParameterMetaData object, you can use the getParameterMetaData methods of the SQLServerPreparedStatement and SQLServerCallableStatement classes.

In the following example, an open connection to the SQL Server 2005 AdventureWorks sample database is passed in to the function, the getParameterMetaData method of the SQLServerCallableStatement class is used to return a SQLServerParameterMetaData object, and then various methods of the SQLServerParameterMetaData object are used to display information about the type and mode of the parameters that are contained within the HumanResources.uspUpdateEmployeeHireInfo stored procedure.

public static void getParameterMetaData(Connection con) {
   try {
      CallableStatement cstmt = con.prepareCall("{call HumanResources.uspUpdateEmployeeHireInfo(?, ?, ?, ?, ?)}");
      ParameterMetaData pmd = cstmt.getParameterMetaData();
      int count = pmd.getParameterCount();
      for (int i = 1; i <= count; i++) {
         System.out.println("TYPE: " + pmd.getParameterTypeName(i) + " MODE: " + pmd.getParameterMode(i));
   catch (Exception e) {

There are some limitations when using the SQLServerParameterMetaData class with prepared statements. When using SQL Server 2008 or 2008 R2, the JDBC driver supports SELECT, DELETE, INSERT, and UPDATE statements as long as these statements does not contain subqueries and/or joins. MERGE queries are also not supported for SQLServerParameterMetaData class when using SQL Server 2008 or 2008 R2. For SQL Server 2012 and higher versions parameter metadata with complex queries are supported.

© 2015 Microsoft