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. The JDBC driver supports SELECT, DELETE, INSERT, and UPDATE statements. However, these statements should not contain subqueries. In addition, the JDBC driver also supports using the IN, IS, and LIKE predicates. For search conditions, the JDBC driver supports using the IS, <, >, LIKE, >=, <=, NOT IN, <>, !>, !<, and != comparative operators. The FREETEXT operator is not supported.

© 2015 Microsoft