The ParameterMetaData Interface

Metadata information can be obtained for the parameters passed to a PreparedStatement or CallableStatement. This information concerns individual parameters defined as ? in the SQL statement and can provide various information such as the SQL type for a parameter, the scale, the associated class, and so on, as listed in the following. PreparedStatement.getParameterMetaData() returns a ParameterMetaData object. This interface was introduced in JDBC version 3.0.

ParameterMetaData Methods for Property Information about Query Parameters

int getParameterCount() java.lang.String getParameterClassName(int param) int getParameterType(int param) java.lang.String getParameterTypeName(int param) int getPrecision(int param) int getScale(int param) int isNullable(int param) boolean isSigned(int param)

The only argument of these methods, except for getParameterCount(), is an integer that identifies the parameter to be analyzed. Values start from 1.

Listing 9-5 provides a short example illustrating the use of these methods.

Listing 9-5: ParameterMetaData: Getting Column Labels

start example
... ... PreparedStatement stmt = conn.prepareStatement("SELECT *  FROM EMPLOYEES WHERE NAME LIKE ?"); ParameterMetaData mtdt = stmt.getParameterMetaData(); System.out.println("The type of the first parameter is: " +  mtdt.getParameterTypeName(1)); if (mtdt.isNullable(1)) {     System.out.println("It allows null values"); } else {     System.out.println("It does not allow null values"); } ... ...
end example



JDBC 3. 0. JAVA Database Connectivity
JDBC 3: Java Database Connectivity
ISBN: 0764548751
EAN: 2147483647
Year: 2002
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net