To query a SQLServerPreparedStatement or a SQLServerCallableStatement object about the parameters that they contain, the Microsoft SQL Server 2005 JDBC Driver 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)); } cstmt.close(); } catch (Exception e) { e.printStackTrace(); } }